Page 1 of 1

PHP function for turning some text lines into a JPG ?

Posted: Tue Oct 28, 2008 11:58 am
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

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

Posted: Tue Oct 28, 2008 12:34 pm
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

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

Posted: Tue Oct 28, 2008 12:44 pm
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
}