tags:

views:

114

answers:

5

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

+5  A: 

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.

Greg
Can I also send this image then in an rss feed?
sanders
+3  A: 

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

vartec
+1  A: 

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

alexn
+1  A: 

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

Alex Reynolds
A: 

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.

Ólafur Waage