Re: Q per adding text to png

From: Date: Wed, 07 Nov 2001 06:40:03 +0000
Subject: Re: Q per adding text to png
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-73676@lists.php.net to get a copy of this message
On Wed, 7 Nov 2001 01:29, Joelmon2001@aol.com wrote: > Hello, I know how to create an image via php but what if I have an > image in the root > called 'button.png' and I simply want to add text to it so button.png > has the text I specify? > > When I *create* images, I can add text just fine. But to overwrite the > blank image to have text? Do I have to have that freetype installed? I > can't use those font commends on win 98 and when I install php 4+ on > linux, I won't know how to call those font commands > > can I just use the same querystring method > $string = urlencode("where"); > > so > ?where=Test > would allow 'test' to be in button.png? > > or is this not allowed in php? > > Thanks I do it regularly - hack around with this script which is originally courtesy of Rasmus <?php Header("Content-type: image/png"); /* 645 x 77 image with background for headers. Background image and font live in $home */ $home = '/usr/local/apache/htdocs/images/source/'; $bkgrd = $home . 'heading_bkgrd.png'; //$font = $home . 'arialbd.ttf'; $font = $home . 'ARIALBD.TTF'; $text = stripslashes($text); /* Font size 24 points unless otherwise defined */ if(!isset($s)) $s=18; if(!isset($text)) $text = "What's New??"; if(!isset($from_left)) $from_left = 10; $size = imagettfbbox($s,0,$font,$text); $dx = abs($size[2]-$size[0]); $dy = abs($size[5]-$size[3]); $im = ImageCreateFromPng($bkgrd); $wide = ImageSX($im); $high = ImageSY($im); //echo "Width = $wide; Height = $high<BR>"; //echo "DX = $dx; DY = $dy<BR>"; //echo ($wide-$dx). '<BR>'; $black = ImageColorAllocate($im, 0,0,0); /* This one centres the text horizontally and vertically */ //ImageTTFText($im, $s, 0, (int)(($wide - $dx)/2 + 1), (int)(($high + $dy)/2), $black, $font, $text); /* This one centres the text vertically and places it $from_left pixels from the left side of the background image */ ImageTTFText($im, $s, 0, $from_left, (int)(($high + $dy)/2 -3), $black, $font, $text); //ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, $font, $text); ImagePng($im); ImageDestroy($im); ?>$im); ImageDestroy($im); ?> -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA DEVICE=EXXON.SYS may mess up your environment

« previous php.general (#73676) next »