Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- plugin.thumb_old.php 2011-08-25 13:22:00.000000000 +0200
- +++ plugin.thumb.php 2011-08-25 13:24:29.000000000 +0200
- @@ -84,7 +84,7 @@
- switch($infos[2]) {
- case 1: $image = imagecreatefromgif($fpath); break;
- - case 2: $image = imagecreatefromjpeg ($fpath); break;
- + case 2: $image = imagecreatefromjpeg($fpath); break;
- case 3: $image = imagecreatefrompng($fpath);
- }
- @@ -93,12 +93,32 @@
- // create empty scaled and copy(resized) the picture
- -
- -
- $scaled = imagecreatetruecolor($new_width, $new_height);
- +
- + /*
- + * If gif or png preserve the alpha channel
- + *
- + * Added by Piero VDFN
- + * Kudos to http://www.php.net/manual/en/function.imagecopyresampled.php#104028
- + */
- + if($infos[2]==1 || $infos[2]==3) {
- + imagecolortransparent($scaled, imagecolorallocatealpha($scaled, 0, 0, 0, 127));
- + imagealphablending($scaled, false);
- + imagesavealpha($scaled, true);
- + $output=$infos[2]==3 ? 'png' : 'gif';
- + } else {
- + $output='jpg';
- + }
- +
- imagecopyresampled($scaled, $image, 0, 0, 0, 0, $new_width, $new_height, $infos[0], $infos[1]);
- - imagejpeg($scaled, $thumbpath);
- + if($output=='png') {
- + imagepng($scaled, $thumbpath);
- + } elseif($output=='gif') {
- + imagegif($scaled, $thumbpath);
- + } else {
- + imagejpeg($scaled, $thumbpath);
- + }
- @chmod($thumbpath, FILE_PERMISSIONS);
- return array($thumbpath, $new_width, $new_height);
Advertisement
Add Comment
Please, Sign In to add comment