aximbigfan Posted November 3, 2008 Share Posted November 3, 2008 Hi, I need to create a function to make an image (600X600) and simply write some text in the center (or wherever) of said image. The image must then be returned in the form of a string. I have never worked with images in PHP, or any other editor other than Mspaint. What is the best place to start? Thanks, Chris Link to comment https://forums.phpfreaks.com/topic/131277-simple-write-some-text-to-an-image/ Share on other sites More sharing options...
DarkWater Posted November 3, 2008 Share Posted November 3, 2008 Use the GD library. There are plenty of tutorials. Check them out, and also read the manual pages on it. Link to comment https://forums.phpfreaks.com/topic/131277-simple-write-some-text-to-an-image/#findComment-681609 Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 PHPThumb is a great tool for lots of stuff like this: http://phpthumb.sourceforge.net/ Link to comment https://forums.phpfreaks.com/topic/131277-simple-write-some-text-to-an-image/#findComment-681614 Share on other sites More sharing options...
aximbigfan Posted November 3, 2008 Author Share Posted November 3, 2008 Ok, thanks guys! I'll check that stuff out. I figured I'd have to learn GD at some point, so I guess now is the time... Chris Link to comment https://forums.phpfreaks.com/topic/131277-simple-write-some-text-to-an-image/#findComment-681630 Share on other sites More sharing options...
aximbigfan Posted November 4, 2008 Author Share Posted November 4, 2008 This is what I made. Sure, it isn't the best of the best, but it works perfectly. You need to have the 'arial.ttf' font file in the same dir as the script for this to work. <?php function texttoimg($input_txt) { $handle = imagecreatetruecolor(600, 600); $white = imagecolorallocate($handle, 255, 255, 255); $black = imagecolorallocate($handle, 0, 0, 0); imagefilledrectangle($handle, 0, 0, 599, 599, $white); imagefttext($handle, 20, 0, 300, 300, $black, './arial.ttf', $input_txt); header('Content-type: image/png'); imagepng($handle); imagedestroy($handle); } texttoimg('Test'); ?> Chris Link to comment https://forums.phpfreaks.com/topic/131277-simple-write-some-text-to-an-image/#findComment-681690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.