diff options
author | Aleksander Machniak <alec@alec.pl> | 2012-12-19 12:27:52 +0100 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2012-12-19 12:27:52 +0100 |
commit | 9ac96015f274b9451377d05001097d0bb7526a27 (patch) | |
tree | 49e7f2a1ae8e0318bec937cb3ede7e58c25ef16e /program | |
parent | c5d7c941aa16b5bd98cfd56f12bbe7c39bddc608 (diff) |
Better GD module functions detection, should fix "Call to undefined function imagecreatefromjpeg()" error
Diffstat (limited to 'program')
-rw-r--r-- | program/lib/Roundcube/rcube_image.php | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/program/lib/Roundcube/rcube_image.php b/program/lib/Roundcube/rcube_image.php index ad96842d2..9695022da 100644 --- a/program/lib/Roundcube/rcube_image.php +++ b/program/lib/Roundcube/rcube_image.php @@ -128,17 +128,20 @@ class rcube_image } // use GD extension - $gd_types = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG); - if ($props['gd_type'] && in_array($props['gd_type'], $gd_types)) { - if ($props['gd_type'] == IMAGETYPE_JPEG) { + if ($props['gd_type']) { + if ($props['gd_type'] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) { $image = imagecreatefromjpeg($this->image_file); } - elseif($props['gd_type'] == IMAGETYPE_GIF) { + else if($props['gd_type'] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) { $image = imagecreatefromgif($this->image_file); } - elseif($props['gd_type'] == IMAGETYPE_PNG) { + else if($props['gd_type'] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')) { $image = imagecreatefrompng($this->image_file); } + else { + // @TODO: print error to the log? + return false; + } $scale = $size / max($props['width'], $props['height']); $width = $props['width'] * $scale; @@ -216,19 +219,22 @@ class rcube_image } // use GD extension (TIFF isn't supported) - $props = $this->props(); - $gd_types = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG); + $props = $this->props(); - if ($props['gd_type'] && in_array($props['gd_type'], $gd_types)) { - if ($props['gd_type'] == IMAGETYPE_JPEG) { + if ($props['gd_type']) { + if ($props['gd_type'] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) { $image = imagecreatefromjpeg($this->image_file); } - else if ($props['gd_type'] == IMAGETYPE_GIF) { + else if ($props['gd_type'] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) { $image = imagecreatefromgif($this->image_file); } - else if ($props['gd_type'] == IMAGETYPE_PNG) { + else if ($props['gd_type'] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')) { $image = imagecreatefrompng($this->image_file); } + else { + // @TODO: print error to the log? + return false; + } if ($type == self::TYPE_JPG) { $result = imagejpeg($image, $filename, 75); |