Jump to content

Upload Thumbnail Transparency


Recommended Posts

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:

 

<?php
$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:

<?php
$image = imagecreatefrompng($filename2);
imagealphablending($image_p, false);
imagesavealpha($image_p, true);
imagepng($image_p, $filename2, 6);

 

and for GIF:

<?php
$image = imagecreatefromgif($filename2);
imagealphablending($image_p, false);
imagesavealpha($image_p, true);
imagegif($image_p, $filename2, 100);

 

can anyone help me?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.