O
O
Oleg2017-05-12 17:12:57
PHP
Oleg, 2017-05-12 17:12:57

How to display text on canvas html5 and php?

There is a code, you need that when you enter site.ru/minecraft.php?text=test
, a picture with the text that is specified in the url is displayed

<?php
$text = $_GET["text"];
$ses = $text;
?>

<!doctype html> 
<html>
  <meta charset='utf-8'>
  <head>
    <title>Minecraft</title>
  <style>
    @font-face {
      font-family: minecraft;
      src: url(minecraft.ttf);
    }
  </style>
  </head>
  <body>
    <canvas id="example" width="320" height="64"></canvas>
    <script>
    var img = new Image();
    img.src = 'achievement.png';
    var canvas = document.getElementById("example");
    var ctx = canvas.getContext("2d");
    ctx.fillStyle = "#ffffff";
    ctx.drawImage(img, 0, 0);
    ctx.font = 'normal 18px minecraft';
    ctx.fillText($ses, 60, 50);
    </script>
  </body>
</html>

<?php
echo $text;
?>

I don't understand what's wrong here.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question