From 2b090dbe79a52520459c7c375b050501293b578f Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 2 May 2015 17:00:17 +0200 Subject: Get supported image types from drivers Signed-off-by: Florian Pritz --- application/controllers/file.php | 3 +-- application/libraries/Image.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'application') diff --git a/application/controllers/file.php b/application/controllers/file.php index 12fb793bd..5e443017c 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -199,8 +199,7 @@ class File extends MY_Controller { $base = explode("/", $filedata["mimetype"])[0]; // TODO: handle video/audio - if ($base == "image" - || in_array($mimetype, array("application/pdf"))) { + if (\libraries\Image::type_supported($mimetype)) { $filedata["tooltip"] = $this->_tooltip_for_image($filedata); $filedata["orientation"] = libraries\Image::get_exif_orientation($file); $this->output_cache->add_merge( diff --git a/application/libraries/Image.php b/application/libraries/Image.php index deefc760d..c6cd20d06 100644 --- a/application/libraries/Image.php +++ b/application/libraries/Image.php @@ -123,6 +123,25 @@ class Image { return $best_driver; } + /** + * Check if a mimetype is supported by the image library. + * + * @param mimetype + * @return true if supported, false otherwise + */ + public static function type_supported($mimetype) + { + try { + $driver = self::best_driver(self::get_image_drivers(), $mimetype); + } catch (\exceptions\ApiException $e) { + if ($e->get_error_id() == "libraries/Image/unsupported-image-type") { + return false; + } + throw $e; + } + return true; + } + /** * Replace the current image by reading in a file * @param file file to read -- cgit v1.2.3-24-g4f1b