pierovdfn

Alpha on thumbs [Flatpress]

Aug 25th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.38 KB | None | 0 0
  1. --- plugin.thumb_old.php    2011-08-25 13:22:00.000000000 +0200
  2. +++ plugin.thumb.php    2011-08-25 13:24:29.000000000 +0200
  3. @@ -84,7 +84,7 @@
  4.    
  5.     switch($infos[2]) {
  6.         case 1: $image = imagecreatefromgif($fpath); break;
  7. -       case 2: $image = imagecreatefromjpeg ($fpath); break;
  8. +       case 2: $image = imagecreatefromjpeg($fpath); break;
  9.         case 3: $image = imagecreatefrompng($fpath);
  10.     }
  11.    
  12. @@ -93,12 +93,32 @@
  13.    
  14.     // create empty scaled and copy(resized) the picture
  15.    
  16. -  
  17. -  
  18.     $scaled = imagecreatetruecolor($new_width, $new_height);
  19. +
  20. +   /*
  21. +    * If gif or png preserve the alpha channel
  22. +    *
  23. +    * Added by Piero VDFN
  24. +    * Kudos to http://www.php.net/manual/en/function.imagecopyresampled.php#104028
  25. +    */
  26. +   if($infos[2]==1 || $infos[2]==3) {
  27. +       imagecolortransparent($scaled, imagecolorallocatealpha($scaled, 0, 0, 0, 127));
  28. +       imagealphablending($scaled, false);
  29. +       imagesavealpha($scaled, true);
  30. +       $output=$infos[2]==3 ? 'png' : 'gif';
  31. +   } else {
  32. +       $output='jpg';
  33. +   }
  34. +
  35.     imagecopyresampled($scaled, $image, 0, 0, 0, 0, $new_width, $new_height, $infos[0], $infos[1]);
  36.    
  37. -   imagejpeg($scaled, $thumbpath);
  38. +   if($output=='png') {
  39. +       imagepng($scaled, $thumbpath);
  40. +   } elseif($output=='gif') {
  41. +       imagegif($scaled, $thumbpath);
  42. +   } else {
  43. +       imagejpeg($scaled, $thumbpath);
  44. +   }
  45.     @chmod($thumbpath, FILE_PERMISSIONS);
  46.    
  47.     return array($thumbpath, $new_width, $new_height);
Advertisement
Add Comment
Please, Sign In to add comment