From c062513b02bcec19e7989d84414103547168afec Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 18 Feb 2025 19:44:38 +0100 Subject: [PATCH] #7340 @1 --- src/Jobs/ProcessFile.php | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Jobs/ProcessFile.php b/src/Jobs/ProcessFile.php index 509b7c9..22b2415 100644 --- a/src/Jobs/ProcessFile.php +++ b/src/Jobs/ProcessFile.php @@ -31,6 +31,8 @@ class ProcessFile protected $quality = 85; + protected $transparent = false; + protected $localBuffer = false; /** @@ -38,13 +40,14 @@ class ProcessFile */ protected $job; - public function __construct($format = 'jpg', $resolution = 150, $quality = 85, $withGraphics = true, $withTexts = true, $version = 'html') + public function __construct($format = 'jpg', $resolution = 150, $quality = 85, $withGraphics = true, $withTexts = true, $transparent = false, $version = 'html') { $this->format = $format; $this->resolution = $resolution; $this->withGraphics = $withGraphics; $this->withTexts = $withTexts; $this->version = $version; + $this->transparent = $transparent && $format === 'png'; $this->setQuality($quality); } @@ -182,7 +185,7 @@ class ProcessFile $minsize = 100; } - $res = $dir . self::getFilename($this->getPage(), $this->getFormat(), $this->getResolution(), $this->getQuality(), $this->isWithGraphics(), $this->isWithTexts(), $this->getVersion()); + $res = $dir . self::getFilename($this->getPage(), $this->getFormat(), $this->getResolution(), $this->getQuality(), $this->isWithGraphics(), $this->isWithTexts(), $this->isTransparent(), $this->getVersion()); $do = false; if (!file_exists($res) || filesize($res) < $minsize) { @@ -197,7 +200,7 @@ class ProcessFile return $res; } - public static function getFilename($page, $format = 'jpg', $resolution = 150, $quality = 85, $withGraphics = true, $withTexts = true, $version = 'html') + public static function getFilename($page, $format = 'jpg', $resolution = 150, $quality = 85, $withGraphics = true, $withTexts = true, $transparent = false, $version = 'html') { $res = ''; if ($format === 'svg') { @@ -214,11 +217,12 @@ class ProcessFile } else if (in_array($format, ['png', 'jpg'])) { $q = ($format === 'jpg' && $quality !== 85) ? '-' . $quality : ''; + $t = ($format === 'png' && $transparent) ? '-transparent' : ''; $prefix = $withTexts ? 't' : 'h'; if ($resolution === 'thumb') { - $res = 'p' . $page . $q . '.' . $format; + $res = 'p' . $page . $q . $t . '.' . $format; } else { - $res = $prefix . $page . '-' . $resolution . $q . '.' . $format; + $res = $prefix . $page . '-' . $resolution . $q . $t . '.' . $format; } } else if ($format === 'swf') { $res = 'p' . $page . '.' . $format; @@ -251,7 +255,7 @@ class ProcessFile PDFTools::makeMiniShot($this->getSplittedPDFPage(), $file, 1, $this->getFormat(), $this->getQuality()); } else { $rr = $this->getVersion() === 'html' ? $this->getResolutionRatio() : $this->getMobileRatio(); - PDFTools::makeShotPNM($this->getSplittedPDFPage(), $file, 1, '', $this->getResolution() * $rr, $this->getQuality(), 4, $this->isWithTexts(), null, null, $this->getFormat()); + PDFTools::makeShotPNM($this->getSplittedPDFPage(), $file, 1, '', $this->getResolution() * $rr, $this->getQuality(), 4, $this->isWithTexts(), $this->isTransparent(), null, null, $this->getFormat()); } } else if ($this->getFormat() === 'swf') { PDFTools::makeSWF($this->getSplittedPDFPage(), $file, 1, $this->getResolution(), $this->getQuality()); @@ -335,4 +339,21 @@ class ProcessFile { $this->quality = max(0, min(100, round((float)$quality))); } + + + /** + * @param bool $transparent + */ + public function setTransparent(bool $transparent): void + { + $this->transparent = $transparent; + } + + /** + * @return bool + */ + public function isTransparent(): bool + { + return $this->transparent; + } } -- 2.39.5