sanders
sanders

Reputation: 10898

Text on a image

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

Upvotes: 0

Views: 683

Answers (5)

Greg
Greg

Reputation: 321638

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.

Upvotes: 6

&#211;lafur Waage
&#211;lafur Waage

Reputation: 70001

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.

Upvotes: 0

Alex Reynolds
Alex Reynolds

Reputation: 96937

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

Upvotes: 1

alexn
alexn

Reputation: 58962

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

Upvotes: 1

vartec
vartec

Reputation: 134601

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

Upvotes: 3

Related Questions