Skip to content

Commit

Permalink
MDL-8855 - Wrote additional GD code to support alpha transparency in …
Browse files Browse the repository at this point in the history
…PNG files.
  • Loading branch information
nicolasconnault committed Mar 13, 2007
1 parent 9eb89d8 commit 831b761
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions mod/data/field/picture/field.class.php
Expand Up @@ -234,6 +234,12 @@ function update_thumbnail($content) {
} 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;

Expand All @@ -243,12 +249,22 @@ function update_thumbnail($content) {

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
Expand Down

0 comments on commit 831b761

Please sign in to comment.