PHP function for turning some text lines into a JPG ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paolosavona
Forum Newbie
Posts: 1
Joined: Tue Oct 28, 2008 11:52 am

PHP function for turning some text lines into a JPG ?

Post by paolosavona »

Hello all.

My code receives some text,
often varying,
and I need to transform it into a .jpg file,
with some very basic formatting.

Is there any function for this?

Thanks.

Paolo
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: PHP function for turning some text lines into a JPG ?

Post by panic! »

Code: Select all

 
 
<?php
 
$im = imagecreatefromstring("HELLO EVERYBODY");
 
    header('Content-Type: image/jpeg');
    imagejpeg($im);
    imagedestroy($im);
 
 
?>
 
 
 



OR

Code: Select all

 
<?php
 
$im = imagecreate(100, 30);
 
// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
 
// Write the string at the top left
imagestring($im, 5, 0, 0, 'HELLO EVERYBODY', $textcolor);
 
// Output the image
header('Content-type: image/jpeg');
 
imagejpeg($im);
imagedestroy($im);
?>
 




http://uk.php.net/manual/en/ref.image.php
pointer
Forum Newbie
Posts: 3
Joined: Tue Oct 28, 2008 8:04 am

Re: PHP function for turning some text lines into a JPG ?

Post by pointer »

Code: Select all

 
function create_jpeg_from_text($text)
{
$im=imagecreate(100,100);//100x100 image
$bg=imagecolorallocate($im, 255,255,255);//white background
$textcolor=imagecolorallocate($im, 0,0,0);//black text
imagestring($im, 5, 0,0, $text, $textcolor);//5:font-size, 0,0: x,y position
imagejpeg($im, "file_name.jpeg", 80);//file_name:to be saved path, 80: quality
}
 
 
Post Reply