]> _ Git - fluidbook_tools.git/commitdiff
#7340 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 18 Feb 2025 18:44:38 +0000 (19:44 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 18 Feb 2025 18:44:38 +0000 (19:44 +0100)
src/Jobs/ProcessFile.php

index 509b7c963c719f65453949d87d0fb4266e9cc00c..22b24153cb84354b0de70b5cfe8c06898b360ddd 100644 (file)
@@ -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;
+    }
 }