aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-08-27 17:03:10 +0200
committerCôme Chilliet <91878298+come-nc@users.noreply.github.com>2024-08-29 17:06:32 +0200
commitb778f3de0a79602ac5054f9919e822c8ac8079a9 (patch)
treeeb24083ba468b3ed27d1e87af1cdcb7cdcbb9ec1 /lib
parentc67e54287ae9432e3a65cc4c55a4a0193ba5702a (diff)
downloadnextcloud-server-b778f3de0a79602ac5054f9919e822c8ac8079a9.tar.gz
nextcloud-server-b778f3de0a79602ac5054f9919e822c8ac8079a9.zip
fix(\OC\Image): Use new IAppConfig and type safe methods
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Image.php34
1 files changed, 12 insertions, 22 deletions
diff --git a/lib/private/Image.php b/lib/private/Image.php
index d49f450c8e9..ca5058e6c65 100644
--- a/lib/private/Image.php
+++ b/lib/private/Image.php
@@ -12,6 +12,7 @@ namespace OC;
use finfo;
use GdImage;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IImage;
use OCP\Server;
@@ -39,6 +40,7 @@ class Image implements IImage {
protected ?string $filePath = null;
private ?finfo $fileInfo = null;
private LoggerInterface $logger;
+ private IAppConfig $appConfig;
private IConfig $config;
private ?array $exif = null;
@@ -47,9 +49,11 @@ class Image implements IImage {
*/
public function __construct(
?LoggerInterface $logger = null,
+ ?IAppConfig $appConfig = null,
?IConfig $config = null,
) {
$this->logger = $logger ?? Server::get(LoggerInterface::class);
+ $this->appConfig = $appConfig ?? Server::get(IAppConfig::class);
$this->config = $config ?? Server::get(IConfig::class);
if (\OC_Util::fileInfoLoaded()) {
@@ -359,28 +363,14 @@ class Image implements IImage {
}
}
- /**
- * @return int
- */
protected function getJpegQuality(): int {
- $quality = $this->config->getAppValue('preview', 'jpeg_quality', (string)self::DEFAULT_JPEG_QUALITY);
- // TODO: remove when getAppValue is type safe
- if ($quality === null) {
- $quality = self::DEFAULT_JPEG_QUALITY;
- }
- return min(100, max(10, (int)$quality));
+ $quality = $this->appConfig->getValueInt('preview', 'jpeg_quality', self::DEFAULT_JPEG_QUALITY);
+ return min(100, max(10, $quality));
}
- /**
- * @return int
- */
protected function getWebpQuality(): int {
- $quality = $this->config->getAppValue('preview', 'webp_quality', (string)self::DEFAULT_WEBP_QUALITY);
- // TODO: remove when getAppValue is type safe
- if ($quality === null) {
- $quality = self::DEFAULT_WEBP_QUALITY;
- }
- return min(100, max(10, (int)$quality));
+ $quality = $this->appConfig->getValueInt('preview', 'webp_quality', self::DEFAULT_WEBP_QUALITY);
+ return min(100, max(10, $quality));
}
private function isValidExifData(array $exif): bool {
@@ -1094,7 +1084,7 @@ class Image implements IImage {
}
public function copy(): IImage {
- $image = new self($this->logger, $this->config);
+ $image = new self($this->logger, $this->appConfig, $this->config);
if (!$this->valid()) {
/* image is invalid, return an empty one */
return $image;
@@ -1119,7 +1109,7 @@ class Image implements IImage {
}
public function cropCopy(int $x, int $y, int $w, int $h): IImage {
- $image = new self($this->logger, $this->config);
+ $image = new self($this->logger, $this->appConfig, $this->config);
$image->imageType = $this->imageType;
$image->mimeType = $this->mimeType;
$image->resource = $this->cropNew($x, $y, $w, $h);
@@ -1128,7 +1118,7 @@ class Image implements IImage {
}
public function preciseResizeCopy(int $width, int $height): IImage {
- $image = new self($this->logger, $this->config);
+ $image = new self($this->logger, $this->appConfig, $this->config);
$image->imageType = $this->imageType;
$image->mimeType = $this->mimeType;
$image->resource = $this->preciseResizeNew($width, $height);
@@ -1137,7 +1127,7 @@ class Image implements IImage {
}
public function resizeCopy(int $maxSize): IImage {
- $image = new self($this->logger, $this->config);
+ $image = new self($this->logger, $this->appConfig, $this->config);
$image->imageType = $this->imageType;
$image->mimeType = $this->mimeType;
$image->resource = $this->resizeNew($maxSize);