Better error handling for GD code

This commit is contained in:
Matthew Barbour
2019-06-12 17:40:43 -05:00
parent f9f4c3bd37
commit 97f60b3ea5
2 changed files with 113 additions and 72 deletions

View File

@ -171,8 +171,14 @@ class RotateImage extends Extension
$background_color = imagecolorallocatealpha($image, 0, 0, 0, 127);
break;
}
if($background_color===false) {
throw new ImageRotateException("Unable to allocate transparent color");
}
$image_rotated = imagerotate($image, $deg, $background_color);
if($image_rotated===false) {
throw new ImageRotateException("Image rotate failed");
}
/* Temp storage while we rotate */
$tmp_filename = tempnam(ini_get('upload_tmp_dir'), 'shimmie_rotate');
@ -181,6 +187,7 @@ class RotateImage extends Extension
}
/* Output to the same format as the original image */
$result = false;
switch ($info[2]) {
case IMAGETYPE_GIF: $result = imagegif($image_rotated, $tmp_filename); break;
case IMAGETYPE_JPEG: $result = imagejpeg($image_rotated, $tmp_filename); break;
@ -191,7 +198,7 @@ class RotateImage extends Extension
throw new ImageRotateException("Unsupported image type.");
}
if($result==false) {
if($result===false) {
throw new ImageRotateException("Could not save image: ".$tmp_filename);
}