The Little Guy Posted September 21, 2007 Share Posted September 21, 2007 OK... I have this function, it looks like this: <?php function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality){ $details = getimagesize("$imageDirectory/$imageName") or die('<div class="container"> <div class="content"> Please only upload images. </div> </div>'); $type = preg_replace('@^.+(?<=/)(.+)$@', '$1', $details['mime']); eval('$srcImg = imagecreatefrom'.$type.'("$imageDirectory/$imageName");'); $thumbHeight = $details[1] * ($thumbWidth / $details[0]); $thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight); imagecolortransparent($thumbImg); imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $details[0], $details[1]); eval('image'.$type.'($thumbImg, "$thumbDirectory/$imageName"'.(($type=='jpeg')?', $quality':'').');'); imagedestroy($srcImg); imagedestroy($thumbImg); } ?> If I use this code: imagecolortransparent($thumbImg); To make the transparent stuff transparent, it doesn't work, but if I change it to this: imagecolortransparent($thumbImg,imagecolorallocate(0,0,0)); it will make the black transparent, but... then I get a weird image, where not only the background is transparent, but the black parts in the foreground of the image are transparent as well. How can I make just the background transparent? Quote Link to comment https://forums.phpfreaks.com/topic/70192-transparent-image/ Share on other sites More sharing options...
Barand Posted September 21, 2007 Share Posted September 21, 2007 One way would be to make the bits that shouldn't be transparent a slightly different color, say (1,1,1) so it's as near black that you won't notice but it will not become tranparent. Quote Link to comment https://forums.phpfreaks.com/topic/70192-transparent-image/#findComment-352614 Share on other sites More sharing options...
The Little Guy Posted September 21, 2007 Author Share Posted September 21, 2007 So how would I know which parts should be transparent? Quote Link to comment https://forums.phpfreaks.com/topic/70192-transparent-image/#findComment-352677 Share on other sites More sharing options...
Barand Posted September 21, 2007 Share Posted September 21, 2007 If you don't know that, how do you know it isn't working correctly now? Quote Link to comment https://forums.phpfreaks.com/topic/70192-transparent-image/#findComment-352680 Share on other sites More sharing options...
The Little Guy Posted September 21, 2007 Author Share Posted September 21, 2007 because, see my Avatar? I am testing it on that... here is the output: http://tzfiles.com/numbers.php Quote Link to comment https://forums.phpfreaks.com/topic/70192-transparent-image/#findComment-352682 Share on other sites More sharing options...
The Little Guy Posted September 21, 2007 Author Share Posted September 21, 2007 Oh yeah.... Here is my new code: <?php $location = "users/ryan/1190402980image.gif"; $details = getimagesize($location); $thumbWidth = 50; $type = preg_replace('@^.+(?<=/)(.+)$@', '$1', $details['mime']); $thumbHeight = $details[1] * ($thumbWidth / $details[0]); $thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight); $background_color = imagecolorallocate($thumbImg, 0, 0, 0); $tans = imagecolortransparent($thumbImg,$background_color); $image = imagecreatefromgif($location); imagepalettecopy($image, $thumbImg); imagegif($thumbImg,NULL); header('Content-Type: image/gif'); imagegif($thumbImg); imagedestroy($thumbImg); ?> Quote Link to comment https://forums.phpfreaks.com/topic/70192-transparent-image/#findComment-352683 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.