Home > Archive > PHP Language > April 2007 > GD write text into image
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
GD write text into image
|
|
| misiek 2007-04-12, 9:57 pm |
| 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
?>
but it only write a text in header actually not saving into image.
Thank You for help
| |
|
| On Thu, 12 Apr 2007 17:05:17 -0500, misiek <michal_augustyniak@gazeta.pl> wrote:
>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
>
>?>
>
>
>but it only write a text in header actually not saving into image.
>
>Thank You for help
i wrote this app last year
http://www.secretsparklegram.com/
it's for cell phones, but the idea is the same adding text over graphics and having php create
images. if this is similar to what you want, i can post code that adds text over images. You'll
have to adapt your to your needs most likely.
| |
| John Murtari 2007-04-13, 6:57 pm |
| 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+$yp
ad,$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/
| |
| misiek 2007-04-13, 9:57 pm |
| >
>
> i wrote this app last year
> http://www.secretsparklegram.com/
> it's for cell phones, but the idea is the same adding text over graphics and having php create
> images. if this is similar to what you want, i can post code that adds text over images. You'll
> have to adapt your to your needs most likely.
>
fajna strona,
to dokladnie czego potrzebuje
prosze podziel sie kodem lub zrodlami
piekne dzieki
|
|
|
|
|