MDL-37308 files: convert_image() now supports transparency.
This commit is contained in:
committed by
Jun Pataleta
parent
b9c333f5db
commit
baddb058a9
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user