corbin Posted February 16, 2007 Share Posted February 16, 2007 So some of y'all may have seen my thumbnail generator thing the other day in the beta testing section... I lost interest a while back after I failed at the transparency aspect, but today I found a new strand of motivation. Anyways what it does (non essential steps not included): -Make a new true color image with the desired width and height (referred to as img1 from now on) -Create an image of the image desired to be a thumb (img2) -Make img1 transparent using the first pixel in it -Copy img2 onto img2 This creates the effect of having transparency around the thumbnail.... I only have one problem. Img2 inherits the transparency setting from img1, and this makes img2 have transparency if it has the color from the first pixel of img1. My first thought was, "OK I'll just copy the transparent one over img1, restraining img1's size and making img2 increase the image size." Sounded good, until I tried to do it and couldn't get it to work:(. Anyway, my question is what is the best method to merge two images and retain transparency without making the image that was merged go transparent? I don't think my code is really necessary to solve the problem, but of course someone will think it is, I'll attach it. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/38706-imagecopyresampled-and-transparency/ Share on other sites More sharing options...
printf Posted February 16, 2007 Share Posted February 16, 2007 Set your transparency to a color or set of colors that don't exist in the image you want to make transparent. You do that by reducing the colors on your image, if it's a true color image, than cycle through the colors until you find one that doesn't exist, then use that color to set your transparency. Link to comment https://forums.phpfreaks.com/topic/38706-imagecopyresampled-and-transparency/#findComment-185925 Share on other sites More sharing options...
corbin Posted February 16, 2007 Author Share Posted February 16, 2007 Hmmm, so I came up with <?php function FindColor() { $r = 0; $g = 0; $b = 0; $match = 0; $i = 0; while($match < 1 && $i <= 16581375) { //while($match < 1 && $i <= 375) { if(imagecolorexact($image, $r, $g, $b) < 0) { $return = array($r, $g, $b); $match = 1; } else { if($r == 255 && $g == 0 && $b == 0) { $rchecked = true; $r = 0; $g = 1; } if($bchecked != true && $rchecked == true && $gchecked == true && $b == 0) { $r = 0; $g = 0; $b = 1; } /* if($g == 255 && $b == 0) { $gchecked = true; $r = 0; $g = 0; } */ if($rchecked != true) { $r++; if($r == 256) { $rchecked = true; } } elseif($rchecked == true && $gchecked != true) { $r++; if($r == 256) { $g++; $r = 0; if($g == 256) { $g = 0; $gchecked = true; } } } elseif($rchecked == true && $gchecked == true && $bchecked != true) { $r++; if($r == 256) { $r = 0; $g++; } if($g == 256) { $g = 0; $b++; } if($b == 256) { $bchecked = true; } } elseif($bchecked == true && $match < 1) { $return = false; } else { $return = false; } } $i++; } return $return; } $image = imagecreatefromjpeg("white.jpg"); global $image; if(!$image) { echo "die bitch"; } $hmm = FindColor($image); //$hmm = imagecolorexact($image, 255, 255, 255); print_r($hmm); //echo $hmm; ?> But I didn't read the note that imagecolorexact doesn't work with jpg... Now I don't know what to do lol... I'll be readin through the GD functions more and messin around with em, but I'm open to suggestions. Link to comment https://forums.phpfreaks.com/topic/38706-imagecopyresampled-and-transparency/#findComment-185968 Share on other sites More sharing options...
printf Posted February 16, 2007 Share Posted February 16, 2007 You don't have to do all that. Can you zip up a a full image and also a thumbnail of that image demonstrating what you want to do. If I see the resulting thumbnail image, I can show you how to do what you want to do. Just remember JPG/JPEG doesn't support transparency, only PNG and GIF support layering alpha channel transparencies. Link to comment https://forums.phpfreaks.com/topic/38706-imagecopyresampled-and-transparency/#findComment-186002 Share on other sites More sharing options...
corbin Posted February 16, 2007 Author Share Posted February 16, 2007 Files are attached... Desired.gif is what I'm trying to achieve. The file in /thumbs/ is what's being created by thumb.php. Index.php simply has a img tag to thumb.php for the image. In images/ is the image the thumb is being created from.... I'm pretty sure what I'm trying to do is easy, but I'm over looking something lol.... I finally decide to look into the GD library and simple stuff stops me >.< lol By the way, thanks a lot for helping! [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/38706-imagecopyresampled-and-transparency/#findComment-186015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.