The Little Guy Posted November 4, 2007 Share Posted November 4, 2007 OK, I am trying to resize transparent GIF images, so I was reading, and they say to use fopen, fread, and read the first 13 bytes... OK, so I read in a transparent gif, and the first 13 bytes... and echo it out to the screen, and I get this: GIF89a›�s�÷�� What am I supposed to do with that? they then say "allocate that color as transparent, and use imagecopy(); to set the transparency back." Can someone help me?? not exactly sure what to do Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 4, 2007 Share Posted November 4, 2007 well the first 13 byes are the first 13 bytes of it. I assume you are goign to read it as binary, but beyond that I dont have an idea. All i know is transparent layers in gifs/pngs are not 100% compliiant. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 4, 2007 Share Posted November 4, 2007 Here is a function Barand helped me out with <?php function uploadThumb($name, $filename, $new_w, $new_h, $ext) { if ($ext == 'jpg'){ $src_img = imagecreatefromjpeg($name); } else if ($ext == 'gif'){ $src_img = imagecreatefromgif($name); } else if ($ext == 'png'){ $src_img = imagecreatefrompng($name); } $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); imagetruecolortopalette($dst_img,false,256); // convert to palletted image $color_00 = imagecolorat($dst_img,0,0); // get background color at 0,0 imagecolortransparent($dst_img, $color_00); // make it transparent if ($ext == 'jpg'){ imagejpeg($dst_img,$filename); } else if ($ext == 'gif'){ imagegif($dst_img,$filename); } else if ($ext == 'png'){ imagepng($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); } ?> It works pretty good. The only problem with it is if you have a pure black area on the picture, it is going to make it transparent. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 4, 2007 Author Share Posted November 4, 2007 Here is the one I found!!! IT WORKS TOO! <?php function transparentGif($imageDirectory,$thumbDirectory, $imageName, $thumbWidth){ $image = imagecreatefromgif("$imageDirectory/$imageName"); $details = getimagesize("$imageDirectory/$imageName"); $thumbHeight = $details[1] * ($thumbWidth / $details[0]); $resized = imagecreatetruecolor($thumbWidth, $thumbHeight); $colorTransparent = imagecolortransparent($image); imagepalettecopy($image, $resized); imagefill($resized, 0, 0, $colorTransparent); imagecolortransparent($resized, $colorTransparent); imagecopyresized($resized, $image, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $details[0], $details[1]); imagegif($resized,"$thumbDirectory/$imageName"); } ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 4, 2007 Share Posted November 4, 2007 Awesome =] Don't forget to solve the topic. 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.