]> _ Git - fluidbook_tools.git/commitdiff
wip #5991 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 5 Jun 2023 11:11:02 +0000 (13:11 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 5 Jun 2023 11:11:02 +0000 (13:11 +0200)
src/Jobs/ProcessFile.php

index c85e2247dc36748dce1e0306095e6facd1365ee8..8383f79a0d5e47d8906e2ed6ccd61300da9e911f 100644 (file)
@@ -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)));
+    }
 }