zq29 Posted April 11, 2007 Share Posted April 11, 2007 I'm trying to rescale a gif file with transparency but am having difficulty with the imagecolortransparent() function - It's not working as I would hope... I'm telling it to replace the colour red with transparency and then overlay my transparent gif, but resized. For some reason, it is turning anything black in my transparent gif, transparent, instead of the red - Can anyone else figure out why it might be doing this? <?php //Load source image $m_source = imagecreatefromgif("im.gif"); //Create destination image $n_source = imagecreatetruecolor(162,23); imagegif($n_source,"a.gif"); //Fill the default black image with red $fill = imagecolorallocate($n_source,255,0,0); imagefill($n_source,0,0,$fill); imagegif($n_source,"b.gif"); //Make red fill transparent imagecolortransparent($n_source,$fill); imagegif($n_source,"c.gif"); //Copy and resize the source image into the destination image imagecopyresized($n_source,$m_source,0,0,0,0,162,23,352,50); imagegif($n_source,"d.gif"); ?> I've attached my im.gif if anyone wants to see what I'm seeing. Many thanks [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/46599-imagecolortransparent-not-working-as-expected-any-ideas/ Share on other sites More sharing options...
neel_basu Posted April 11, 2007 Share Posted April 11, 2007 I am not Sure that teh Rasta of that image is pure red so that you cant use red 255 and others 0. Find the appropiate color of that Rasta's Red Link to comment https://forums.phpfreaks.com/topic/46599-imagecolortransparent-not-working-as-expected-any-ideas/#findComment-227071 Share on other sites More sharing options...
Barand Posted April 11, 2007 Share Posted April 11, 2007 What's the final image supposed to look like? Link to comment https://forums.phpfreaks.com/topic/46599-imagecolortransparent-not-working-as-expected-any-ideas/#findComment-227219 Share on other sites More sharing options...
neel_basu Posted April 12, 2007 Share Posted April 12, 2007 Rasta Vanished Link to comment https://forums.phpfreaks.com/topic/46599-imagecolortransparent-not-working-as-expected-any-ideas/#findComment-227387 Share on other sites More sharing options...
zq29 Posted April 12, 2007 Author Share Posted April 12, 2007 I know the word 'Rasta' is not pure red, I'm not trying to make that part transparent, pure coincidence on that part. I'm trying to take a gif with a transparent background, resize it, crop it and overlay it over a jpeg. This was the only step that was giving me an issue. Not to worry too much though now, I have rewritten the whole process using ImageMagick - Although GD might have produced a slightly better looking output, I was getting a bit frustrated with it! Might be interesting still though to see why my snippet of code above was not doing as expected though... Thanks for your input guys. Link to comment https://forums.phpfreaks.com/topic/46599-imagecolortransparent-not-working-as-expected-any-ideas/#findComment-227433 Share on other sites More sharing options...
Barand Posted April 12, 2007 Share Posted April 12, 2007 Looks like im.gif background is already transparent so this works (if I understood OK) <?php $im = imagecreatefromjpeg('desert sands.jpg'); $im1 = imagecreatefromgif('im.gif'); $w1 = imagesx($im1); $h1 = imagesy($im1); imagecopyresampled($im, $im1, 40,40,0,0, $w1/2, $h1/2, $w1, $h1); header ("content-type: image/jpeg"); imagejpeg($im); imagedestroy($im); imagedestroy($im1); ?> Link to comment https://forums.phpfreaks.com/topic/46599-imagecolortransparent-not-working-as-expected-any-ideas/#findComment-227876 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.