Mouse Posted March 17, 2007 Share Posted March 17, 2007 Well I have had a little play with this and I am not clear on a couple of bits… <?php $point = 18; $text = "Bekky"; // to be users name here $size = imagettfbbox($point, 0, "ARIAL", $text); $xsize = abs($size[0]) + abs($size[2]); $ysize = abs($size[5]) + abs($size[1]); $image = imagecreatefrompng("images/badge/sml_nm_tg.png"); $imagesize = getimagesize("images/badge/sml_nm_tg.png"); $textleftpos = round(($imagesize[0] - $xsize) / 2); $texttoppos = round(($imagesize[1] + $ysize) / 2) + 10; $red = ImageColorAllocate($image, 255, 51, 0); $grey = ImageColorAllocate($image, 102, 153, 153); imagettftext($image, $point, 0, $textleftpos + 1, $texttoppos + 1, $grey, "ARIAL", $text); imagettftext($image, $point, 0, $textleftpos, $texttoppos, $red, "ARIAL", $text); header("content-type: image/png"); imagepng($image); imagedestroy($image); ?> as you can see there is meant to be red writing with a grey drop shadow but as you can see from this local test screen print… <img src="http://mouse.nodstrum.com/images/badge/demo.jpg" /> it just isn’t doing the colours thing… even worse <a href="http://mouse.nodstrum.com/nametag.php">when I try this online I get gibberish</a> any ideas? PLEASE???? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 17, 2007 Share Posted March 17, 2007 Try using the function imagecolorclosest() instead of imagecolorallocat(). The reason you're getting "gibberish" online is that you're getting warning messages about not being able to find the font you want. Those warnings put out headers which stop the image from displaying as an image. The "gibberish" is the image as displayed with ASCII characters. Ken Quote Link to comment Share on other sites More sharing options...
Mouse Posted March 17, 2007 Author Share Posted March 17, 2007 Ken, using the function imagecolorclosest() instead of imagecolorallocat() has done the trick, many thanks. The reason you're getting "gibberish" online is that you're getting warning messages about not being able to find the font you want. how can i rectify this, is there a way to find out which fonts are on the server (i assume) or can i put one in there? Many thanks Mouse Quote Link to comment Share on other sites More sharing options...
Barand Posted March 17, 2007 Share Posted March 17, 2007 try this (change the font file path as required) <?php $point = 18; $text = "Bekky"; // to be users name here define ("ARIAL", "c:/windows/fonts/ARIAL.TTF"); // font in ttf function is the font file $size = imagettfbbox($point, 0, ARIAL, $text); $xsize = $size[2] - $size[0]; // size is the diff between left and right cooords, not the sum $ysize = $size[3] - $size[1]; $image = imagecreatefrompng("images/badge/sml_nm_tg.png"); $width = imagesx($image); $height = imagesy($image); $textleftpos = round(($width - $xsize) / 2); $texttoppos = round(($height - $ysize) / 2) + 10; $red = ImageColorAllocate($image, 255, 51, 0); $grey = ImageColorAllocate($image, 102, 153, 153); imagettftext($image, $point, 0, $textleftpos + 1, $texttoppos + 1, $grey, ARIAL, $text); imagettftext($image, $point, 0, $textleftpos, $texttoppos, $red, ARIAL, $text); header("content-type: image/png"); imagepng($image); imagedestroy($image); ?> Quote Link to comment Share on other sites More sharing options...
Mouse Posted March 17, 2007 Author Share Posted March 17, 2007 Many thanks sir but the Define didn't work it out... also isn't that counterproductive if the site user is a a mac or linux addict? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 17, 2007 Share Posted March 17, 2007 (change the font file path as required) Quote Link to comment Share on other sites More sharing options...
Mouse Posted March 18, 2007 Author Share Posted March 18, 2007 how would i go about saving the new image in a selected file? whilst preserving the transparency??? Quote Link to comment Share on other sites More sharing options...
fert Posted March 18, 2007 Share Posted March 18, 2007 imagepng($im,"file.png"); Quote Link to comment Share on other sites More sharing options...
Mouse Posted March 18, 2007 Author Share Posted March 18, 2007 Thanks Fret!!!! Were Done! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.