From: Vincent Vanwaelscappel Date: Mon, 5 Jun 2023 11:11:02 +0000 (+0200) Subject: wip #5991 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=3908281da50b77b1a785a64a0faa7e8c4bd22327;p=fluidbook_tools.git wip #5991 @0.25 --- diff --git a/src/Jobs/ProcessFile.php b/src/Jobs/ProcessFile.php index c85e224..8383f79 100644 --- a/src/Jobs/ProcessFile.php +++ b/src/Jobs/ProcessFile.php @@ -25,17 +25,20 @@ class ProcessFile { */ protected $version = 'html'; + protected $quality = 85; + /** * @var ProcessPage */ protected $job; - public function __construct($format = 'jpg', $resolution = 150, $withGraphics = true, $withTexts = true, $version = 'html') { + public function __construct($format = 'jpg', $resolution = 150, $withGraphics = true, $withTexts = true, $version = 'html', $quality = 85) { $this->format = $format; $this->resolution = $resolution; $this->withGraphics = $withGraphics; $this->withTexts = $withTexts; $this->version = $version; + $this->setQuality($quality); } /** @@ -208,13 +211,13 @@ class ProcessFile { } } else if (in_array($this->getFormat(), ['png', 'jpg'])) { if ($this->getResolution() === 'thumb') { - PDFTools::makeMiniShot($this->getSplittedPDFPage(), $file, 1, $this->getFormat()); + 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, 85, 4, $this->isWithTexts(), null, null, $this->getFormat()); + PDFTools::makeShotPNM($this->getSplittedPDFPage(), $file, 1, '', $this->getResolution() * $rr, $this->getQuality(), 4, $this->isWithTexts(), null, null, $this->getFormat()); } } else if ($this->getFormat() === 'swf') { - PDFTools::makeSWF($this->getSplittedPDFPage(), $file, 1, $this->getResolution(), 80); + PDFTools::makeSWF($this->getSplittedPDFPage(), $file, 1, $this->getResolution(), $this->getQuality()); } unlink($lock); if (!file_exists($file)) { @@ -247,7 +250,6 @@ class ProcessFile { } - public function makeOptimizedSVGFile($out) { $in = $this->makeSVGFile(); SVGTools::optimizeSVGImages($in, $out, $this->getResolution()); @@ -261,4 +263,18 @@ class ProcessFile { } return $res; } + + /** + * @return int + */ + public function getQuality(): int { + return $this->quality; + } + + /** + * @param int $quality + */ + public function setQuality(int $quality): void { + $this->quality = max(0, min(100, round($quality))); + } }