Upload Thumbnail Transparency

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JustinMs66
Forum Contributor
Posts: 127
Joined: Sun Sep 03, 2006 4:18 pm

Upload Thumbnail Transparency

Post by JustinMs66 »

i have upload code that makes a thumbnail of the image.
but with GIF and PNG files it dosnt save the transparency in the thumbnail, it just makes it black.
is there any way to save the transparency in the thumbnail?

the thumbnail code i have:

Code: Select all

$filename = "test.jpg";
$filename2 = "test_thumbnail.jpg";
$width = 180;
$height = 180;

list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}
$image_p = imagecreatetruecolor($width, $height);

imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
but here is the main code i have for php resize:

Code: Select all

$image = imagecreatefrompng($filename2);
imagealphablending($image_p, false);
imagesavealpha($image_p, true);
imagepng($image_p, $filename2, 6);
and for GIF:

Code: Select all

$image = imagecreatefromgif($filename2);
imagealphablending($image_p, false);
imagesavealpha($image_p, true);
imagegif($image_p, $filename2, 100);
can anyone help me?
Post Reply