]> source.dussan.org Git - nextcloud-server.git/commitdiff
make it possible to influence output type of \OC_Image
authorGeorg Ehrke <developer@georgehrke.com>
Fri, 14 Mar 2014 10:13:45 +0000 (11:13 +0100)
committerGeorg Ehrke <developer@georgehrke.com>
Fri, 14 Mar 2014 10:13:45 +0000 (11:13 +0100)
lib/private/image.php

index a4a23f0f097940d5df9566b3a33a732d61e57654..df49bf9848d89f260ba2656b6ef3749adb6cd409 100644 (file)
@@ -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;