diff options
author | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-12-16 22:09:36 +0000 |
---|---|---|
committer | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-12-16 22:09:36 +0000 |
commit | 1f2d77b380af1992fa58b03fd2f8c07fa7486459 (patch) | |
tree | 9236e97107ddde441a3a62be72027daa9fd910db /includes | |
parent | b7a2becd1538da11419387d3f76d21d06847c6f1 (diff) | |
download | brdo-1f2d77b380af1992fa58b03fd2f8c07fa7486459.tar.gz brdo-1f2d77b380af1992fa58b03fd2f8c07fa7486459.tar.bz2 |
#200338 by m3avrck and quicksketch: fix transparent GIF resizing
Diffstat (limited to 'includes')
-rw-r--r-- | includes/image.gd.inc | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/includes/image.gd.inc b/includes/image.gd.inc index 61d4b3929..7ae60dcf1 100644 --- a/includes/image.gd.inc +++ b/includes/image.gd.inc @@ -80,7 +80,7 @@ function image_gd_resize($source, $destination, $width, $height) { return FALSE; } - $res = imageCreateTrueColor($width, $height); + $res = imagecreatetruecolor($width, $height); if ($info['extension'] == 'png') { $transparency = imagecolorallocatealpha($res, 0, 0, 0, 127); imagealphablending($res, FALSE); @@ -88,11 +88,29 @@ function image_gd_resize($source, $destination, $width, $height) { imagealphablending($res, TRUE); imagesavealpha($res, TRUE); } - imageCopyResampled($res, $im, 0, 0, 0, 0, $width, $height, $info['width'], $info['height']); + elseif ($info['extension'] == 'gif') { + // If we have a specific transparent color. + $transparency_index = imagecolortransparent($im); + if ($transparency_index >= 0) { + // Get the original image's transparent color's RGB values. + $transparent_color = imagecolorsforindex($im, $transparency_index); + // Allocate the same color in the new image resource. + $transparency_index = imagecolorallocate($res, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']); + // Completely fill the background of the new image with allocated color. + imagefill($res, 0, 0, $transparency_index); + // Set the background color for new image to transparent. + imagecolortransparent($res, $transparency_index); + // Find number of colors in the images palette. + $number_colors = imagecolorstotal($im); + // Convert from true color to palette to fix transparency issues. + imagetruecolortopalette($res, TRUE, $number_colors); + } + } + imagecopyresampled($res, $im, 0, 0, 0, 0, $width, $height, $info['width'], $info['height']); $result = image_gd_close($res, $destination, $info['extension']); - imageDestroy($res); - imageDestroy($im); + imagedestroy($res); + imagedestroy($im); return $result; } |