Ticket #2805: wp_create_thumbnail-preserve-PNG-transparency-ideal.diff
File wp_create_thumbnail-preserve-PNG-transparency-ideal.diff, 1.3 KB (added by , 19 years ago) |
---|
-
wp-admin/admin-functions.php
828 828 } 829 829 830 830 $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height); 831 832 if( $type[2] == 3 and function_exists( 'imagealphablending' ) and function_exists( 'imagesavealpha' ) ) { 833 // Preserve PNG transparency, from http://php.net/manual/en/function.imagecopyresampled.php#44134 834 if (function_exists('imageantialias')) 835 imageantialias($thumbnail, TRUE); // not necessary, but not always available 836 imagealphablending($thumbnail, false); 837 imagesavealpha($thumbnail,true); 838 $transparent = imagecolorallocatealpha($thumbnail, 255, 255, 255, 0); 839 for($x=0;$x<$image_new_width;$x++) { 840 for($y=0;$y<$image_new_height;$y++) { 841 imagesetpixel( $thumbnail, $x, $y, $transparent ); 842 } 843 } 844 } 845 831 846 @ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]); 832 847 833 848 // If no filters change the filename, we'll do a default transformation. … … 861 876 if (!empty ($error)) { 862 877 return $error; 863 878 } else { 864 return $thumb path;879 return $thumb; 865 880 } 866 881 } 867 882