summaryrefslogtreecommitdiffstats
path: root/lib/private/image.php
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2014-03-14 11:13:45 +0100
committerGeorg Ehrke <developer@georgehrke.com>2014-03-14 11:13:45 +0100
commit6f96ab3e9093d03088ebd6bde399edf2d1ba2fac (patch)
treef77c72a35369db08ac96b1bbfa2d37827b997ff2 /lib/private/image.php
parentb2757e621c1dfd9d9993636e74bdebf01dce51e0 (diff)
downloadnextcloud-server-6f96ab3e9093d03088ebd6bde399edf2d1ba2fac.tar.gz
nextcloud-server-6f96ab3e9093d03088ebd6bde399edf2d1ba2fac.zip
make it possible to influence output type of \OC_Image
Diffstat (limited to 'lib/private/image.php')
-rw-r--r--lib/private/image.php47
1 files 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;