sneamia Posted July 29, 2008 Share Posted July 29, 2008 <? $img = imagecreatefromgif('resources/sig_bg.gif'); $background = imagecolorallocate($img, 0, 0, 0); $white = imagecolorallocate($img, 255, 255, 255); $bbox = imagettfbbox(16, 0, 'resources/CALIBRIB.TTF', 'wrong'); imagettftext($img, 16, 0, 455 - $bbox[2], 70, $white, 'resources/CALIBRIB.TTF', 'wrong'); header('Content-type: image/png'); imagepng($img); imagedestroy($img); ?> As you can see, I open an image stored locally on my server. It then uses imagettftext to write white text on the image. However, this is where it screws up. The text it writes is black, not white. I'm not entirely sure what I am doing wrong. Any ideas? I tried $img = imagecreate(500, 100); and it writes the text correctly, with the correct color. It seems like there is something incompatible when I use imagecreatefromgif and imagettftext. Quote Link to comment https://forums.phpfreaks.com/topic/117209-solved-imagettftext-does-not-use-the-color-i-specify/ Share on other sites More sharing options...
d.shankar Posted July 29, 2008 Share Posted July 29, 2008 Try now dude this will work <?php $img = imagecreatefromgif('resources/sig_bg.gif'); $background = imagecolorallocate($img, 0, 0, 0); $white = imagecolorallocate($img, 255, 255, 255); $bbox = imagettfbbox(16, 0, 'resources/CALIBRIB.TTF', 'wrong'); imagettftext($img, 16, 0, 455 - $bbox[2], 70, $white, 'resources/CALIBRIB.TTF', 'wrong'); header('Content-type: image/png'); imagegif($img); imagedestroy($img); ?> Quote Link to comment https://forums.phpfreaks.com/topic/117209-solved-imagettftext-does-not-use-the-color-i-specify/#findComment-602939 Share on other sites More sharing options...
sneamia Posted July 29, 2008 Author Share Posted July 29, 2008 Honestly, why do you think exporting as a gif would change the color of the text? It doesn't work for me. And you also keep the header as image/png while exporting imagegif. Quote Link to comment https://forums.phpfreaks.com/topic/117209-solved-imagettftext-does-not-use-the-color-i-specify/#findComment-602941 Share on other sites More sharing options...
d.shankar Posted July 29, 2008 Share Posted July 29, 2008 Then atleast you must use a PNG Image [code=php:0] $im = imagecreatefrompng($image_path); [/code] The only way. Quote Link to comment https://forums.phpfreaks.com/topic/117209-solved-imagettftext-does-not-use-the-color-i-specify/#findComment-602944 Share on other sites More sharing options...
sneamia Posted July 29, 2008 Author Share Posted July 29, 2008 Can you explain what that has to do with text color? Quote Link to comment https://forums.phpfreaks.com/topic/117209-solved-imagettftext-does-not-use-the-color-i-specify/#findComment-602947 Share on other sites More sharing options...
d.shankar Posted July 29, 2008 Share Posted July 29, 2008 Can i know something ?? Why are u trying to mix up PNG and GIF .. is this how PHP GD suggests you to use ?? My code is running perfect here. I dont what's up with your side. ?? Quote Link to comment https://forums.phpfreaks.com/topic/117209-solved-imagettftext-does-not-use-the-color-i-specify/#findComment-602949 Share on other sites More sharing options...
Barand Posted July 29, 2008 Share Posted July 29, 2008 Strange one. I had to use my own gif and font (arial) but your code worked fine - white text ??? ??? @d.shankar GIF was converted to GD image format GD image was converted to PNG on output. Nothing wrong with that. In fact that's how to convert a file from one format to another. Quote Link to comment https://forums.phpfreaks.com/topic/117209-solved-imagettftext-does-not-use-the-color-i-specify/#findComment-602966 Share on other sites More sharing options...
GingerRobot Posted July 29, 2008 Share Posted July 29, 2008 I agree; very strange. My only thought is that it might be something to do with the fact that gifs are limited to 256 colours. I'm not sure if that could possibly cause a problem though. I wonder if you could perhaps supply the image you're working with so I could test it with that. Also, what version of PHP and GD are you using? Quote Link to comment https://forums.phpfreaks.com/topic/117209-solved-imagettftext-does-not-use-the-color-i-specify/#findComment-602976 Share on other sites More sharing options...
Barand Posted July 29, 2008 Share Posted July 29, 2008 (Just had same thought, GR) I wonder if it's a pallette issue. Check the value of $white. If it's -1 the allocation failed. (Full pallette?) In that case try $white = imagecolorexact($img, 255,255,255) // if it's already in pallette or $white = imagecolorclosest($img, 255,255,255) // get nearest to white from pallette Quote Link to comment https://forums.phpfreaks.com/topic/117209-solved-imagettftext-does-not-use-the-color-i-specify/#findComment-602979 Share on other sites More sharing options...
sneamia Posted July 29, 2008 Author Share Posted July 29, 2008 Yea, it seemed to be the color palette. I just stuck with png. Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/117209-solved-imagettftext-does-not-use-the-color-i-specify/#findComment-602981 Share on other sites More sharing options...
corbin Posted July 29, 2008 Share Posted July 29, 2008 White was probably the transparency color, and it was being made black for some reason.... I guess that's what you meant by palette problem though. ;p Quote Link to comment https://forums.phpfreaks.com/topic/117209-solved-imagettftext-does-not-use-the-color-i-specify/#findComment-602997 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.