par123 Posted September 21, 2009 Share Posted September 21, 2009 Hi, I am trying to create images using imagecreatetruecolor function. It creates an image with black background by default. Now, I want to make the background transparent. I used imagecolortransparent function for that. I am trying to write a string in the image in white font. For creating the white color, I use imagecolorallocate function. When I pass the image resource of my image as an argument to this funtion, the whole image becomes white. I tried using the imagecolortransparent funtion at the end after writing the string, but it does not work. I am using Php 5.3. Can someone please help? I am too much frustrated with this now. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 21, 2009 Share Posted September 21, 2009 Hi par123, Post your code and we'll be able to give a more definitive answer. Thanks Quote Link to comment Share on other sites More sharing options...
par123 Posted September 21, 2009 Author Share Posted September 21, 2009 Here is my code: header ("Content-type: image/png"); $im = imagecreatetruecolor(100, 100) or die("!ERROR!"); $black=imagecolorallocate($im,0,0,0); imagecolortransparent($im,$black); function imagestringcentered ($img,$font,$text,$color) { while (strlen($text) * imagefontwidth($font) > imagesx($img)) { if ($font > 1) { $font--; } else { break; } } $cy = (imagesy($img)/2) - (imagefontheight($font)/2); imagestring($img,$font,imagesx($img) / 2 - strlen($text) * imagefontwidth($font) / 2,$cy,$text,$color); } $w = trim(stripslashes($_GET['w'])); if(!$w || $w == "") $w = "!NO DATA!"; $tc = imagecolorallocate($im,255,255,255); imagestringcentered($im, 5, $w, $tc); imagepng($im); imagedestroy($im); Quote Link to comment Share on other sites More sharing options...
par123 Posted September 21, 2009 Author Share Posted September 21, 2009 I am trying to create a transparent background image with text written in the center of the image in white font. I have posted my code in the previous post. Can someone please tell me why soes the background not turn transparent? Rest all works fine. Just the backgroound does not turn transparent. I am working on it since long, but am not able to figure it out. Can someone please help? Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 21, 2009 Share Posted September 21, 2009 Just of curiosity, what image file extension is it? Quote Link to comment Share on other sites More sharing options...
par123 Posted September 21, 2009 Author Share Posted September 21, 2009 It is a .png image file. Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 21, 2009 Share Posted September 21, 2009 Sorry, just seen that in your code (I am not good with image manipulation). While we wait for a more knowledged response... you are not using IE6 right? That has a png/transparent deficiency that requires hacking Quote Link to comment Share on other sites More sharing options...
par123 Posted September 21, 2009 Author Share Posted September 21, 2009 Thanks for your response! I am not using IE6. I am using Firefox 3.5 and Chrome. So thats not a problem. Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 21, 2009 Share Posted September 21, 2009 $tc = imagecolorallocate($im,255,255,255); is that setting the background.. the image, to white? Just stabbing away till someone else can fix ya up. Quote Link to comment Share on other sites More sharing options...
par123 Posted September 21, 2009 Author Share Posted September 21, 2009 No, it does not make the background white. With the code posted, I am able to get the white font string in black background image. But I want the background to be transparent. So I tried using imagecreate function instead of imagecreatetruecolor. I know imagecreate would create an image with no background color. I need white color for the font. So inorder to create white color, when I use imagecolorallocate, it makes the background white. There must be some other way of making the background transparent. Imagecolortransparent function too does not work. 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.