MDL-37308 files: convert_image() now supports transparency.

This commit is contained in:
Adrian Greeve
2015-11-29 20:28:28 -06:00
committed by Jun Pataleta
parent b9c333f5db
commit baddb058a9
+10 -1
View File
@@ -1556,7 +1556,16 @@ class file_storage {
$img = imagecreatefromstring($file->get_content());
if ($height != $newheight or $width != $newwidth) {
$newimg = imagecreatetruecolor($newwidth, $newheight);
if (!imagecopyresized($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height)) {
// Maintain transparency.
if ($filerecord['mimetype'] == 'image/png' || $filerecord['mimetype'] == 'image/gif') {
$colour = imagecolorallocatealpha($newimg, 0, 0, 0, 127);
imagecolortransparent($newimg, $colour);
imagealphablending($newimg, false);
imagesavealpha($newimg, true);
}
if (!imagecopyresampled($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height)) {
// weird
throw new file_exception('storedfileproblem', 'Can not resize image');
}