From f7cec5cf56192d4782c8a48aa737395279361bcd Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Tue, 13 Mar 2007 02:40:18 +0000 Subject: [PATCH] MDL-8855 - Wrote additional GD code to support alpha transparency in PNG files. --- mod/data/field/picture/field.class.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/mod/data/field/picture/field.class.php b/mod/data/field/picture/field.class.php index 39cff6a016..0aa2bd54bc 100755 --- a/mod/data/field/picture/field.class.php +++ b/mod/data/field/picture/field.class.php @@ -246,6 +246,12 @@ class data_field_picture extends data_field_file { } else { $im1 = ImageCreate($thumbwidth,$thumbheight); } + + // Prevent alpha blending for PNG images + if ($image->type == 3) { + imagealphablending($im1, false); + } + $cx = $image->width / 2; $cy = $image->height / 2; @@ -255,12 +261,22 @@ class data_field_picture extends data_field_file { ImageCopyBicubic($im1, $im, 0, 0, $cx-$halfwidth, $cy-$halfheight, $thumbwidth, $thumbheight, $halfwidth*2, $halfheight*2); - - if (function_exists('ImageJpeg')) { + + // Save alpha transparency for PNG images + if ($image->type == 3) { + imagesavealpha($im1, true); + } + + if (function_exists('ImageJpeg') && $image->type != 3) { @touch($thumbnaillocation); // Helps in Safe mode if (ImageJpeg($im1, $thumbnaillocation, 90)) { @chmod($thumbnaillocation, 0666); } + } elseif (function_exists('ImagePng') && $image->type == 3) { + @touch($thumbnaillocation); // Helps in Safe mode + if (ImagePng($im1, $thumbnaillocation, 9)) { + @chmod($thumbnaillocation, 0666); + } } } else { // Try and remove the thumbnail - we don't want thumbnailing active -- 2.39.5