From 6f96ab3e9093d03088ebd6bde399edf2d1ba2fac Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 14 Mar 2014 11:13:45 +0100 Subject: [PATCH] make it possible to influence output type of \OC_Image --- lib/private/image.php | 47 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/lib/private/image.php b/lib/private/image.php index a4a23f0f097..df49bf9848d 100644 --- a/lib/private/image.php +++ b/lib/private/image.php @@ -150,9 +150,12 @@ class OC_Image { * @brief Outputs the image. * @returns bool */ - public function show() { - header('Content-Type: '.$this->mimeType()); - return $this->_output(); + public function show($mimeType=null) { + if($mimeType === null) { + $mimeType = $this->mimeType(); + } + header('Content-Type: '.$mimeType); + return $this->_output(null, $mimeType); } /** @@ -161,20 +164,23 @@ class OC_Image { * @param string $filePath */ - public function save($filePath=null) { + public function save($filePath=null, $mimeType=null) { + if($mimeType === null) { + $mimeType = $this->mimeType(); + } if($filePath === null && $this->filePath === null) { OC_Log::write('core', __METHOD__.'(): called with no path.', OC_Log::ERROR); return false; } elseif($filePath === null && $this->filePath !== null) { $filePath = $this->filePath; } - return $this->_output($filePath); + return $this->_output($filePath, $mimeType); } /** * @brief Outputs/saves the image. */ - private function _output($filePath=null) { + private function _output($filePath=null, $mimeType=null) { if($filePath) { if (!file_exists(dirname($filePath))) mkdir(dirname($filePath), 0777, true); @@ -192,7 +198,34 @@ class OC_Image { return false; } - switch($this->imageType) { + $imageType = null; + if($mimeType !== null) { + switch($mimeType) { + case 'image/gif': + $this->imageType = IMAGETYPE_GIF; + break; + case 'image/jpeg': + case 'image/pjpeg': + $this->imageType = IMAGETYPE_JPEG; + break; + case 'image/png': + $this->imageType = IMAGETYPE_PNG; + break; + case 'image/x-xbitmap': + $this->imageType = IMAGETYPE_XBM; + break; + case 'image/bmp': + $this->imageType = IMAGETYPE_BMP; + break; + default: + $this->imageType = IMAGETYPE_PNG; + break; + } + } else { + $imageType = $this->imageType; + } + + switch($imageType) { case IMAGETYPE_GIF: $retVal = imagegif($this->resource, $filePath); break; -- 2.39.5