|
Posted by John Murtari on 04/13/07 15:56
misiek <michal_augustyniak@gazeta.pl> writes:
> Is it possible to write a some text to the image and save it to other
> name useing GD library and functions ?
>
> If yes can you tell me which function I gotta use maybe same samples ?
>
> I was trying using this script
>
> <?php
>
> srand((double)microtime()*1234567); // Start the random gizmo
> $image = imagecreatefromgif("google.gif"); // Get a background
>
> $font =
> "/opt/sun-jdk-1.5.0.10/jre/lib/fonts/LucidaTypewriterRegular.ttf"; //
> Get a font
>
> $textcolor = imagecolorallocate($image,0,0,0); // Set text color
>
> $text1 = "FR. 4/23"; // Here is our text
>
> imagefttext($image, 50, 0, 20, 50, $textcolor, $font, $text1); //
> Write the text with a font
>
> header("Content-type: image/jpeg"); // Its a JPEG
> imagegif($image,'',90); // Zap it to the browser
> imagedestroy($image); // Memory Freeupage
We have some working example using PHP at:
http://www.thebook-demo.com/php/
It is CRUCIAL that you don't output any blank lines
before the "Content-type" - that often causes problems..
The source is:
<?
Header("Content-type: image/png");
// note - must use the absolute font path
// be careful about blank lines in your code which will output a blank and confuse browser
$text = "This is a PHP Button";
$font = "/pub/comwww/thebook-demo/php/gd/fonts/arial.ttf";
if(!isset($s)) $s=11;
$size = imagettfbbox($s,0,$font,$text);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$xpad=19;
$ypad=19;
$im = imagecreate($dx+$xpad,$dy+$ypad);
$blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white);
ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, "$font", $text);
ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white, "$font", $text);
Imagepng($im);
ImageDestroy($im);
?>
--
John
___________________________________________________________________
John Murtari Software Workshop Inc.
jmurtari@following domain 315.635-1968(x-211) "TheBook.Com" (TM)
http://thebook.com/
[Back to original message]
|