Text on a image

后端 未结 5 1235
南旧
南旧 2021-01-17 04:27

Is it possible to dynamically place text on an image in php? And then send it to an rss feed?

相关标签:
5条回答
  • 2021-01-17 04:46

    Of course. With imagefttext() from GD. You'll need TTF files though.

    0 讨论(0)
  • 2021-01-17 04:48

    Yes, can use either the GD functions or the ImageMagick functions, depending on which is installed on your server and which you prefer.

    Using GD it would go something like this:

    <?php
    $img = imagecreatefromjpeg('my.jpg');
    $textColor = imagecolorallocate($img, 0, 0, 0); // black text
    
    imagefttext($img, 13, 0, 105, 55, $textColor, './arial.ttf', 'Hello World');
    
    // Output image to the browser
    header('Content-Type: image/jpeg');
    imagejpeg($img);
    
    // Or save to file
    imagejpeg($img, 'my-text.jpg');
    
    imagedestroy($img);
    ?>
    

    Edit:

    To put the image into your RSS feed you would save it to a file and put the URL into your feed.

    0 讨论(0)
  • 2021-01-17 04:58

    Remember to cache that file in some way. Since both GD and Imagick are heavy on the server and can take some time to create.

    0 讨论(0)
  • 2021-01-17 05:02

    Here are some ImageMagick libraries for PHP. Once you have that installed, you might annotate your image with relevant PHP'ed ImageMagick commands.

    0 讨论(0)
  • 2021-01-17 05:13

    You can use GD with the imagecreatefromjpeg (or any other format), and then imageftttext to draw the string.

    0 讨论(0)
提交回复
热议问题