MasterACE14 Posted November 11, 2007 Share Posted November 11, 2007 Afternoon Everyone, I have a script which basically puts in 2 words into a PNG image, what I want to do is, center the text horizontally, set the font to Arial, and make the text slightly transparent. here is my script: <?php // variables $testing = "Alpha Testing"; $image = "http://www.crikeygames.com.au/conflictingforces/images/conflicting_forces_header.png"; $im = imagecreatefrompng($image); $wc = ImageColorAllocate ($im, 255, 255, 255); $red = ImageColorAllocate ($im, 255, 0, 0); ImageString($im, 3, 260, 2, $testing, $wc); header("Content-Type: image/png"); Imagepng($im,'',100); ImageDestroy ($im); ?> any help is greatly appreciated Regards ACE Link to comment https://forums.phpfreaks.com/topic/76811-text-within-a-png-image/ Share on other sites More sharing options...
Daukan Posted November 11, 2007 Share Posted November 11, 2007 You will need to use getimagesize() to get the size of the image Then use imagepstext() to place the text You can subtract the pixels used in the text from the image width, divide that in half and use that as the starting point for the text. Link to comment https://forums.phpfreaks.com/topic/76811-text-within-a-png-image/#findComment-388900 Share on other sites More sharing options...
cooldude832 Posted November 11, 2007 Share Posted November 11, 2007 that won't "center" it it will just put it int he middle, to "center it" you will need to find the length of it and the length of the string in pixels, then subtract the two and split the difference, however this should be already built. Link to comment https://forums.phpfreaks.com/topic/76811-text-within-a-png-image/#findComment-388904 Share on other sites More sharing options...
TutorMe Posted November 11, 2007 Share Posted November 11, 2007 $string = "Your Text Here"; $im = imagecreatefrompng("bg.png"); $orange = imagecolorallocate($im, 0, 0, 0); $px = (imagesx($im) - 7.5 * strlen($string)) / 2; imagestring($im, 3, $px, 9, $string, $orange); imagepng($im); imagedestroy($im); I didn't really modify this code, but you should be able to, to get it to say what you want. It centers the text. It's also the wrong font. I'm not sure how to change that. Sorry. Hope this helps a little. Link to comment https://forums.phpfreaks.com/topic/76811-text-within-a-png-image/#findComment-388905 Share on other sites More sharing options...
MasterACE14 Posted November 11, 2007 Author Share Posted November 11, 2007 I've now got it centered nicely, But I still don't know how to make it transparent(the string) and make it Arial font? current code: <?php // variables $testing = "Alpha Testing"; $image = "http://www.crikeygames.com.au/conflictingforces/images/conflicting_forces_header.png"; $im = imagecreatefrompng($image); $wc = ImageColorAllocate ($im, 255, 255, 255); $red = ImageColorAllocate ($im, 255, 0, 0); $px = (imagesx($im) - 7.5 * strlen($testing)) / 2; ImageString($im, 3, $px, 16, $testing, $wc); header("Content-Type: image/png"); Imagepng($im,'',100); ImageDestroy ($im); ?> Regards ACE Link to comment https://forums.phpfreaks.com/topic/76811-text-within-a-png-image/#findComment-388911 Share on other sites More sharing options...
MasterACE14 Posted November 11, 2007 Author Share Posted November 11, 2007 <bump> Link to comment https://forums.phpfreaks.com/topic/76811-text-within-a-png-image/#findComment-388945 Share on other sites More sharing options...
Daukan Posted November 11, 2007 Share Posted November 11, 2007 If the text is always the same you could make an image that has transparency already and merge it onto the main image. Basically a watermark. You can google for php watermarks and find some good scripts already written. Link to comment https://forums.phpfreaks.com/topic/76811-text-within-a-png-image/#findComment-388950 Share on other sites More sharing options...
yzerman Posted November 11, 2007 Share Posted November 11, 2007 http://www.php.net/manual/en/function.imageloadfont.php Not sure if this helps or not. This means you will have to find the arial font file on your server and point to it. Link to comment https://forums.phpfreaks.com/topic/76811-text-within-a-png-image/#findComment-388956 Share on other sites More sharing options...
MasterACE14 Posted November 11, 2007 Author Share Posted November 11, 2007 ok, thanks guys Link to comment https://forums.phpfreaks.com/topic/76811-text-within-a-png-image/#findComment-388967 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.