diff options
author | Joas Schilling <coding@schilljs.com> | 2017-02-22 12:11:42 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-02-22 14:53:15 +0100 |
commit | 1e281bc616fc0034a4098999cf83d0d1115f5bb8 (patch) | |
tree | a9a5556712ec96fb146d4773c363d29fbde3e23b /lib/private/legacy/image.php | |
parent | 182bfd9f2365483c4516c7ed4eb12948c5e66193 (diff) | |
download | nextcloud-server-1e281bc616fc0034a4098999cf83d0d1115f5bb8.tar.gz nextcloud-server-1e281bc616fc0034a4098999cf83d0d1115f5bb8.zip |
Use 90% JPEG quality for thumbnails and previews by default
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/legacy/image.php')
-rw-r--r-- | lib/private/legacy/image.php | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/private/legacy/image.php b/lib/private/legacy/image.php index 47f2a977e9c..05367bbfde4 100644 --- a/lib/private/legacy/image.php +++ b/lib/private/legacy/image.php @@ -54,6 +54,8 @@ class OC_Image implements \OCP\IImage { private $fileInfo; /** @var \OCP\ILogger */ private $logger; + /** @var \OCP\IConfig */ + private $config; /** @var array */ private $exif; @@ -79,12 +81,17 @@ class OC_Image implements \OCP\IImage { * @param resource|string $imageRef The path to a local file, a base64 encoded string or a resource created by * an imagecreate* function. * @param \OCP\ILogger $logger + * @param \OCP\IConfig $config */ - public function __construct($imageRef = null, $logger = null) { + public function __construct($imageRef = null, $logger = null, \OCP\IConfig $config = null) { $this->logger = $logger; if (is_null($logger)) { $this->logger = \OC::$server->getLogger(); } + $this->config = $config; + if ($config === null) { + $this->config = \OC::$server->getConfig(); + } if (\OC_Util::fileInfoLoaded()) { $this->fileInfo = new finfo(FILEINFO_MIME_TYPE); @@ -267,7 +274,7 @@ class OC_Image implements \OCP\IImage { $retVal = imagegif($this->resource, $filePath); break; case IMAGETYPE_JPEG: - $retVal = imagejpeg($this->resource, $filePath); + $retVal = imagejpeg($this->resource, $filePath, $this->getJpegQuality()); break; case IMAGETYPE_PNG: $retVal = imagepng($this->resource, $filePath); @@ -319,7 +326,12 @@ class OC_Image implements \OCP\IImage { $res = imagepng($this->resource); break; case "image/jpeg": - $res = imagejpeg($this->resource); + $quality = $this->getJpegQuality(); + if ($quality !== null) { + $res = imagejpeg($this->resource, null, $quality); + } else { + $res = imagejpeg($this->resource); + } break; case "image/gif": $res = imagegif($this->resource); @@ -343,6 +355,17 @@ class OC_Image implements \OCP\IImage { } /** + * @return int|null + */ + protected function getJpegQuality() { + $quality = $this->config->getAppValue('preview', 'jpeg_quality', 90); + if ($quality !== null) { + $quality = min(100, max(10, (int) $quality)); + } + return $quality; + } + + /** * (I'm open for suggestions on better method name ;) * Get the orientation based on EXIF data. * |