]> _ Git - cubeextranet.git/commitdiff
wait #3905 @2
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 22 Sep 2020 17:59:30 +0000 (17:59 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 22 Sep 2020 17:59:30 +0000 (17:59 +0000)
inc/ws/Metier/class.ws.book.parametres.php
inc/ws/Metier/class.ws.document.php
inc/ws/Util/class.ws.pdf.convert.php
inc/ws/Util/html5/master/class.ws.html5.compiler.php

index 74fac27c4961f258eeb57ca556116c3170d2012e..4b594a7abf6617c9bbfc163bdcfb76b37bd0f068 100644 (file)
@@ -188,9 +188,11 @@ class wsBookParametres extends wsParametres
         $this->fields['centerBook'] = array('type' => 'boolean', 'default' => true, 'editable' => true, 'label' => __('Centrer la publication sur les couvertures'), 'grade' => 2);
         $this->fields['correctCenter'] = array('type' => 'boolean', 'default' => true, 'editable' => true, 'label' => __('Corriger les lignes blanches entre les pages'), 'grade' => 2);
         $this->fields['maxResolution'] = array('type' => 'combo', 'default' => 300, 'editable' => true, 'datas' => array('300dpi' => 300, '150dpi' => 150), 'grade' => 2, 'label' => __('Résolution maximale des pages'));
+        $this->fields['imageFormat'] = array('type' => 'combo', 'default' => 'jpg', 'editable' => true, 'datas' => array(/*__('Le plus léger') => 'best', */
+            'JPEG' => 'jpg', 'PNG' => 'png'), 'grade' => 2, 'label' => __('Format des images'));
         $this->fields['dynamicBackgroundColor'] = ['type' => 'textarea', 'default' => '', 'editable' => true, 'label' => 'Couleur de fond dynamique', 'grade' => 3];
         $this->forms['3d_mode'] = array('label' => __('Options de visualisation'),
-            'fieldsnames' => array('visualisationMode', 'antialiasReading', 'correctCenter', 'pagesBaseAngle', 'centerBook', '|', 'extraXSpace', 'extraYSpace', '|', 'viewMode', '|', 'dynamicBackgroundColor', '|', 'maxResolution'));
+            'fieldsnames' => array('visualisationMode', 'antialiasReading', 'correctCenter', 'pagesBaseAngle', 'centerBook', '|', 'extraXSpace', 'extraYSpace', '|', 'viewMode', '|', 'dynamicBackgroundColor', '|', 'imageFormat', 'maxResolution'));
 
         $this->fields['preload'] = array('type' => 'integer', 'default' => 16, 'editable' => true, 'label' => __('Nombre de pages à précharger'), 'grade' => 3);
 
index 1db28b0b51a37a432ac3bace35ed31d32f7412de..d3cd66ec9f03d6308d2ba410a045d5ee7bfd94f3 100644 (file)
@@ -110,7 +110,7 @@ class wsDocument extends cubeMetier
     public function copyOriginalFromOlderVersion()
     {
         if (!file_exists($this->in)) {
-          //  copy('https://ws.fluidbook.com/docs/' . $this->document_id . '/original.pdf', $this->in);
+            //  copy('https://ws.fluidbook.com/docs/' . $this->document_id . '/original.pdf', $this->in);
         }
     }
 
@@ -556,16 +556,17 @@ class wsDocument extends cubeMetier
 
     protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null, $texts = true)
     {
-        if (is_null($in)) {
-            $in = $this->getCroppedPDF();
-        }
-
         $tmp = cubeFiles::tempnam();
+        $pttopx = 1;
+
+        $s = $this->generalInfos['page'][$page]['size'];
+        $w = floor(($s[0] * $pttopx) * ($resolution / 72));
+        $h = floor(($s[1] * $pttopx) * ($resolution / 72));
 
         $antialiasing = $antialiasing ? 'yes' : 'no';
         $freetype = $texts ? 'yes' : 'no';
         // Exporte les fichiers
-        $pdftoppm = new cubeCommandLine('pdftoppm', null, true);
+        $pdftoppm = new CubeIT_CommandLine('pdftoppm', null, true);
         $pdftoppm->setPath(CONVERTER_PATH);
 
         $pdftoppm->setArg('f', 1);
@@ -576,14 +577,17 @@ class wsDocument extends cubeMetier
         $pdftoppm->setArg('-aa ' . $antialiasing);
         $pdftoppm->setArg('-aaVector ' . $antialiasing);
         $pdftoppm->setArg('r', $resolution);
+        $pdftoppm->setArg('W', $w);
+        $pdftoppm->setArg('H', $h);
         $pdftoppm->setArg(null, $this->getSplittedPDFPage($page));
         $pdftoppm->setArg(null, $tmp);
         $pdftoppm->execute();
-        $this->addToLog($pdftoppm, true, $page);
+        $pdftoppm->debug();
 
         $tmp .= '.ppm';
 
         $jpegfile = $this->out . $prefix . $page . '.jpg';
+        $pngfile = $this->out . $prefix . $page . '.png';
 
         if (file_exists($tmp)) {
             //                 $pnmtojpeg = new cubeCommandLine('pnmtojpeg', $jpegfile, false);
@@ -593,13 +597,18 @@ class wsDocument extends cubeMetier
             //                 $this->addToLog($pnmtojpeg, false, $page);
 
 
-            $cjpeg = new cubeCommandLine('cjpeg', null, true);
+            $cjpeg = new cubeCommandLine('/opt/mozjpeg/bin/cjpeg', null, true);
             $cjpeg->setArg('-quality ' . ($quality + 6));
             $cjpeg->setArg('-outfile ' . $jpegfile);
             $cjpeg->setArg(null, $tmp);
             $cjpeg->execute();
             $this->addToLog($cjpeg, false, $page);
 
+            $pnmtopng = new CubeIT_CommandLine('pnmtopng', $pngfile, false);
+            $pnmtopng->setArg('-background white');
+            $pnmtopng->setArg(null, $tmp);
+            $pnmtopng->execute();
+
             unlink($tmp);
         }
     }
@@ -1132,11 +1141,11 @@ class wsDocument extends cubeMetier
 //        return $d0;
     }
 
-    public static function makeHTML5FilesIfNotExists($document_id, $document_page)
+    public static function makeHTML5FilesIfNotExists($document_id, $document_page, $format = 'jpg')
     {
         global $core;
 
-        $path = self::getDir($document_id) . '/html/h150-' . $document_page . '.jpg';
+        $path = self::getDir($document_id) . '/html/h150-' . $document_page . '.' . $format;
         if (!file_exists($path)) {
             $dao = new wsDAODocument($core->con);
             $doc = $dao->selectById($document_id);
@@ -1144,11 +1153,11 @@ class wsDocument extends cubeMetier
         }
     }
 
-    public static function makeMobileFirstFilesIfNotExists($document_id, $document_page)
+    public static function makeMobileFirstFilesIfNotExists($document_id, $document_page, $format = 'jpg')
     {
         global $core;
 
-        $path = self::getDir($document_id) . '/mf/h150-' . $document_page . '.jpg';
+        $path = self::getDir($document_id) . '/mf/h150-' . $document_page . '.' . $format;
         if (!file_exists($path)) {
             $dao = new wsDAODocument($core->con);
             $doc = $dao->selectById($document_id);
index aa7ed7c4b08cd320ab16a6cb7af40af7c16f6f99..7ee4fcbb3b886825088e4bfd19bf21d834a452d2 100644 (file)
  * Date: 17/11/2016\r
  * Time: 14:24\r
  */\r
-class wsPDFConvert {\r
-\r
-       public static function makeMiniShot($in, $out, $page) {\r
-               self::makeShotFixedWidth($in, $out, $page, 'p', 500, 65, 4, 'PNM');\r
-       }\r
-\r
-       public static function makeShotFixedWidth($in, $out, $page, $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'PNM') {\r
-               // Make thumbs of $w width\r
-               self::makeShot($in, $out, $page, $prefix, null, $quality, $antialiasing, $method, $w, -1);\r
-       }\r
-\r
-       public static function makeShotFixedHeight($in, $out, $page, $prefix = '', $h = '', $quality = 90, $antialiasing = 4, $method = 'PNM') {\r
-               // Make thumbs of $h height\r
-               self::makeShot($in, $out, $page, $prefix, null, $quality, $antialiasing, $method, -1, $h);\r
-       }\r
-\r
-       public static function makeShot($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'PNM', $width = null, $height = null) {\r
-               $error = false;\r
-               if ($method == 'GS') {\r
-                       self::makeShotGS($in, $out, $page, $prefix, $resolution, $quality, $antialiasing, $width, $height);\r
-               } elseif ($method == 'PNM') {\r
-                       self::makeShotPNM($in, $out, $page, $prefix, $resolution, $quality, $antialiasing, true, $width, $height);\r
-               }\r
-               // Test the result by checking all files\r
-               if (!file_exists($out)) {\r
-                       $error = true;\r
-               }\r
-               // If error, we try to make thumbs with other method\r
-               if ($error) {\r
-                       if ($method == 'GS') {\r
-                               self::makeShotPNM($in, $out, $page, $prefix, $resolution, $quality, $antialiasing, true, $width, $height);\r
-                       } elseif ($method == 'PNM') {\r
-                               self::makeShotGS($in, $out, $page, $prefix, $resolution, $quality, $antialiasing, $width, $height);\r
-                       }\r
-               }\r
-       }\r
-\r
-       protected static function makeShotGS($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $width = null, $height = null) {\r
-\r
-               // Fabrication des thumbanails avec ghostscript\r
-               $gs = new cubeCommandLine('gs', null, true);\r
-               $gs->setPath(CONVERTER_PATH);\r
-               $gs->setEnv('GS_FONTPATH', FONT_PATH);\r
-               $gs->setArg('-dBATCH');\r
-               $gs->setArg('-dNOPAUSE');\r
-               $gs->setArg('-dNOPROMPT');\r
-               // Antialias\r
-               $gs->setArg('-dDOINTERPOLATE');\r
-               $gs->setArg('-dTextAlphaBits=' . $antialiasing);\r
-               $gs->setArg('-dGraphicsAlphaBits=' . $antialiasing);\r
-               // Device\r
-               $gs->setArg('-sDEVICE=jpeg');\r
-               // Dispotion & colors\r
-               // $gs->setArg('-dUseCIEColor');\r
-               $gs->setArg('-dAutoRotatePages=/None');\r
-               $gs->setArg('-dUseCropBox');\r
-               // Resolution & Quality\r
-               $gs->setArg('-r' . round($resolution));\r
-               $gs->setArg('-dJPEGQ=' . $quality);\r
-               // Performances\r
-               $gs->setArg('-dNumRenderingThreads=4');\r
-               // Page range\r
-               $gs->setArg('-dFirstPage=' . $page);\r
-               $gs->setArg('-dLastPage=' . $page);\r
-               // Files\r
-               $gs->setArg('-sOutputFile=' . $out);\r
-\r
-               $gs->setArg(null, $in);\r
-               $gs->execute();\r
-       }\r
-\r
-       protected static function makeShotPNM($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $texts = true, $width = null, $height = null) {\r
-               $tmp = cubeFiles::tempnam();\r
-\r
-               $antialiasing = $antialiasing ? 'yes' : 'no';\r
-               $freetype = $texts ? 'yes' : 'no';\r
-               // Exporte les fichiers\r
-               $pdftoppm = new cubeCommandLine('pdftoppm', null, true);\r
-               $pdftoppm->setPath(CONVERTER_PATH);\r
-\r
-               $pdftoppm->setArg('f', $page);\r
-               $pdftoppm->setArg('l', $page);\r
-               $pdftoppm->setArg('-cropbox');\r
-               $pdftoppm->setArg('-freetype ' . $freetype);\r
-               $pdftoppm->setArg('-singlefile');\r
-               $pdftoppm->setArg('-aa ' . $antialiasing);\r
-               $pdftoppm->setArg('-aaVector ' . $antialiasing);\r
-               if (null !== $resolution) {\r
-                       $pdftoppm->setArg('r', $resolution);\r
-               }\r
-               if (null !== $width) {\r
-                       $pdftoppm->setArg('-scale-to-x ' . $width);\r
-               }\r
-               if (null !== $height) {\r
-                       $pdftoppm->setArg('-scale-to-y ' . $height);\r
-               }\r
-               $pdftoppm->setArg(null, $in);\r
-               $pdftoppm->setArg(null, $tmp);\r
-               $pdftoppm->execute();\r
-               $tmp .= '.ppm';\r
-\r
-\r
-               if (file_exists($tmp)) {\r
-                       $cjpeg = new cubeCommandLine('cjpeg', null, true);\r
-                       $cjpeg->setArg('-quality ' . ($quality + 6));\r
-                       $cjpeg->setArg('-outfile ' . $out);\r
-                       $cjpeg->setArg(null, $tmp);\r
-                       $cjpeg->execute();\r
-                       unlink($tmp);\r
-               }\r
-       }\r
-       public static function getThumbFromPDF($pdf, $page) {\r
-               if (!file_exists($pdf)) {\r
-                       return false;\r
-               }\r
-               $dir = WS_CACHE . '/thumbs/' . sha1($pdf) . '/';\r
-               if (!file_exists($dir)) {\r
-                       mkdir($dir, 0777, true);\r
-               }\r
-               $jpeg = $dir . '/p' . $page . '.jpg';\r
-               $mtime = filemtime($jpeg);\r
-\r
-               if (!file_exists($jpeg) || $mtime < filemtime(__FILE__) || $mtime < filemtime($pdf)) {\r
-                       wsPDFConvert::makeMiniShot($pdf, $jpeg, $page);\r
-               }\r
-\r
-               return $jpeg;\r
-       }\r
+class wsPDFConvert\r
+{\r
+\r
+    public static function makeMiniShot($in, $out, $page, $format = 'jpg')\r
+    {\r
+        self::makeShotFixedWidth($in, $out, $page, 'p', 500, 65, 4, 'PNM', $format);\r
+    }\r
+\r
+    public static function makeShotFixedWidth($in, $out, $page, $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'PNM', $format = 'jpg')\r
+    {\r
+        // Make thumbs of $w width\r
+        self::makeShot($in, $out, $page, $prefix, null, $quality, $antialiasing, $method, $w, -1, $format);\r
+    }\r
+\r
+    public static function makeShotFixedHeight($in, $out, $page, $prefix = '', $h = '', $quality = 90, $antialiasing = 4, $method = 'PNM', $format = 'jpg')\r
+    {\r
+        // Make thumbs of $h height\r
+        self::makeShot($in, $out, $page, $prefix, null, $quality, $antialiasing, $method, -1, $h, $format);\r
+    }\r
+\r
+    public static function makeShot($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'PNM', $width = null, $height = null, $format = 'jpg')\r
+    {\r
+        $error = false;\r
+        if ($method == 'GS') {\r
+            self::makeShotGS($in, $out, $page, $prefix, $resolution, $quality, $antialiasing, $width, $height, $format);\r
+        } elseif ($method == 'PNM') {\r
+            self::makeShotPNM($in, $out, $page, $prefix, $resolution, $quality, $antialiasing, true, $width, $height, $format);\r
+        }\r
+        // Test the result by checking all files\r
+        if (!file_exists($out)) {\r
+            $error = true;\r
+        }\r
+        // If error, we try to make thumbs with other method\r
+        if ($error) {\r
+            if ($method == 'GS') {\r
+                self::makeShotPNM($in, $out, $page, $prefix, $resolution, $quality, $antialiasing, true, $width, $height, $format);\r
+            } elseif ($method == 'PNM') {\r
+                self::makeShotGS($in, $out, $page, $prefix, $resolution, $quality, $antialiasing, $width, $height, $format);\r
+            }\r
+        }\r
+    }\r
+\r
+    protected static function makeShotGS($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $width = null, $height = null, $format = 'jpg')\r
+    {\r
+\r
+        // Fabrication des thumbanails avec ghostscript\r
+        $gs = new cubeCommandLine('gs', null, true);\r
+        $gs->setPath(CONVERTER_PATH);\r
+        $gs->setEnv('GS_FONTPATH', FONT_PATH);\r
+        $gs->setArg('-dBATCH');\r
+        $gs->setArg('-dNOPAUSE');\r
+        $gs->setArg('-dNOPROMPT');\r
+        // Antialias\r
+        $gs->setArg('-dDOINTERPOLATE');\r
+        $gs->setArg('-dTextAlphaBits=' . $antialiasing);\r
+        $gs->setArg('-dGraphicsAlphaBits=' . $antialiasing);\r
+        // Device\r
+        $device = $format === 'jpg' ? 'jpeg' : 'png16m';\r
+        $gs->setArg('-sDEVICE=' . $device);\r
+        // Dispotion & colors\r
+        // $gs->setArg('-dUseCIEColor');\r
+        $gs->setArg('-dAutoRotatePages=/None');\r
+        $gs->setArg('-dUseCropBox');\r
+        // Resolution & Quality\r
+        $gs->setArg('-r' . round($resolution));\r
+        if ($format === 'jpg') {\r
+            $gs->setArg('-dJPEGQ=' . $quality);\r
+        }\r
+        // Performances\r
+        $gs->setArg('-dNumRenderingThreads=4');\r
+        // Page range\r
+        $gs->setArg('-dFirstPage=' . $page);\r
+        $gs->setArg('-dLastPage=' . $page);\r
+        // Files\r
+        $gs->setArg('-sOutputFile=' . $out);\r
+\r
+        $gs->setArg(null, $in);\r
+        $gs->execute();\r
+    }\r
+\r
+    protected static function makeShotPNM($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $texts = true, $width = null, $height = null, $format = 'jpg')\r
+    {\r
+        $tmp = cubeFiles::tempnam();\r
+\r
+        $antialiasing = $antialiasing ? 'yes' : 'no';\r
+        $freetype = $texts ? 'yes' : 'no';\r
+        // Exporte les fichiers\r
+        $pdftoppm = new cubeCommandLine('pdftoppm', null, true);\r
+        $pdftoppm->setPath(CONVERTER_PATH);\r
+\r
+        $pdftoppm->setArg('f', $page);\r
+        $pdftoppm->setArg('l', $page);\r
+        $pdftoppm->setArg('-cropbox');\r
+        $pdftoppm->setArg('-freetype ' . $freetype);\r
+        $pdftoppm->setArg('-singlefile');\r
+        $pdftoppm->setArg('-aa ' . $antialiasing);\r
+        $pdftoppm->setArg('-aaVector ' . $antialiasing);\r
+        if (null !== $resolution) {\r
+            $pdftoppm->setArg('r', $resolution);\r
+        }\r
+        if (null !== $width) {\r
+            $pdftoppm->setArg('-scale-to-x ' . $width);\r
+        }\r
+        if (null !== $height) {\r
+            $pdftoppm->setArg('-scale-to-y ' . $height);\r
+        }\r
+        $pdftoppm->setArg(null, $in);\r
+        $pdftoppm->setArg(null, $tmp);\r
+        $pdftoppm->execute();\r
+        $tmp .= '.ppm';\r
+\r
+\r
+        if (file_exists($tmp)) {\r
+            if ($format === 'jpg') {\r
+                $cjpeg = new cubeCommandLine('/opt/mozjpeg/bin/cjpeg', null, true);\r
+                $cjpeg->setArg('-quality ' . ($quality + 6));\r
+                $cjpeg->setArg('-outfile ' . $out);\r
+                $cjpeg->setArg(null, $tmp);\r
+                $cjpeg->execute();\r
+            } else if ($format === 'png') {\r
+                $pnmtopng = new CubeIT_CommandLine('pnmtopng', $out, false);\r
+                $pnmtopng->setArg('-background white');\r
+                $pnmtopng->setArg(null, $tmp);\r
+                $pnmtopng->execute();\r
+            }\r
+            unlink($tmp);\r
+        }\r
+    }\r
+\r
+    public static function getThumbFromPDF($pdf, $page, $format = 'jpg')\r
+    {\r
+        if (!file_exists($pdf)) {\r
+            return false;\r
+        }\r
+        $dir = WS_CACHE . '/thumbs/' . sha1($pdf) . '/';\r
+        if (!file_exists($dir)) {\r
+            mkdir($dir, 0777, true);\r
+        }\r
+        $image = $dir . '/p' . $page . '.' . $format;\r
+        $mtime = filemtime($image);\r
+\r
+        if (!file_exists($image) || $mtime < filemtime(__FILE__) || $mtime < filemtime($pdf)) {\r
+            wsPDFConvert::makeMiniShot($pdf, $image, $page, $format);\r
+        }\r
+\r
+        return $image;\r
+    }\r
 \r
 }
\ No newline at end of file
index b0ecd4cc95b66ca0596107e87e0149a9f32952b4..5ccc6c73e7457fe168a4054dc89081c38dc4e156 100644 (file)
@@ -234,6 +234,7 @@ class wsHTML5Compiler
         $this->multiApp = $this->home = $home;
         $this->version = $version;
 
+
         if ($version == 'stable') {
             $this->assets = WS_COMPILE_ASSETS . '/player/branches/master';
         } else if ($version == 'dev') {
@@ -289,8 +290,10 @@ class wsHTML5Compiler
         $this->width = round($size[0], 8);
         $this->height = round($size[1], 8);
 
-        wsDocument::makeHTML5FilesIfNotExists($this->pages[1]['document_id'], $this->pages[1]['document_page']);
-        $firstJpeg = wsDocument::getDir($this->pages[1]['document_id']) . 'html/h150-' . $this->pages[1]['document_page'] . '.jpg';
+        $this->imageFormat = $this->book->parametres->imageFormat;
+
+        wsDocument::makeHTML5FilesIfNotExists($this->pages[1]['document_id'], $this->pages[1]['document_page'], $this->imageFormat);
+        $firstJpeg = wsDocument::getDir($this->pages[1]['document_id']) . 'html/h150-' . $this->pages[1]['document_page'] . '.' . $this->imageFormat;
 
         $imagesize = CubeIT_Image::getimagesize($firstJpeg);
         $this->pdf2htmlRatio = round(($imagesize[0] * 0.48) / $this->width, 12);
@@ -308,7 +311,6 @@ class wsHTML5Compiler
 
         $this->scale = 1;
 
-
         $this->numerotation = explode(',', $this->book->numerotation);
 
         if ($this->isMobileFirst()) {
@@ -1857,7 +1859,7 @@ class wsHTML5Compiler
             $thisimagesvg = !$thisrasterize && $this->svg;
             $thisbackgroundPrefix = $thisrasterize ? ['t'] : $this->backgroundsPrefix;
 
-            wsDocument::$makeFunction($infos['document_id'], $infos['document_page']);
+            wsDocument::$makeFunction($infos['document_id'], $infos['document_page'], $this->imageFormat);
 
             foreach ($this->getResolutions() as $r) {
                 foreach ($thisbackgroundPrefix as $backgroundsPrefix) {
@@ -1865,13 +1867,13 @@ class wsHTML5Compiler
                     if ($backgroundsPrefix === 'p') {
                         $srcPrefix = 'h';
                     }
-                    $source = $docdir . $imdir . '/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg';
+                    $source = $docdir . $imdir . '/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.' . $this->imageFormat;
                     if ($r == 150 && file_exists($source)) {
                         $firstDoc = $daoDoc->selectById($infos['document_id']);
                         $d = $firstDoc->generalInfos['page'][$infos['document_page']]['size'];
                         $this->config->pagesDimensions[$page] = array($this->cssWidth, $d[1] * ($this->cssWidth / $d[0]));
                     }
-                    $ok = $this->vdir->copy($source, 'data/background/' . $r . '/' . $backgroundsPrefix . $page . '.jpg');
+                    $ok = $this->vdir->copy($source, 'data/background/' . $r . '/' . $backgroundsPrefix . $page . '.' . $this->imageFormat);
                     if (!$ok && $r = 300) {
                         $this->maxRes = 150;
                     }
@@ -1905,14 +1907,18 @@ class wsHTML5Compiler
 
             $thumb = false;
             if ($this->book->parametres->pdfThumbnails) {
-                $thumb = wsPDFConvert::getThumbFromPDF(WS_BOOKS . '/working/' . $this->book->book_id . '/' . $this->book->parametres->pdfThumbnails, $page);
+                $thumb = wsPDFConvert::getThumbFromPDF(WS_BOOKS . '/working/' . $this->book->book_id . '/' . $this->book->parametres->pdfThumbnails, $page, $this->imageFormat);
             }
             if (!$thumb) {
-                $thumb = $docdir . 'p' . $infos['document_page'] . '.jpg';
+
+                $thumb = $docdir . 'p' . $infos['document_page'] . '.' . $this->imageFormat;
+                if (!file_exists($thumb)) {
+                    $doc = $daoDoc->selectById($infos['document_id']);
+                    $doc->makeMiniShot($infos['document_page']);
+                }
             }
 
-            $thumbs[$page] = $thumb;
-            $this->vdir->copy($thumb, 'data/thumbnails/p' . $page . '.jpg');
+            $this->vdir->copy($thumb, 'data/thumbnails/p' . $page . '.' . $this->imageFormat);
 
             if ($page == 1) {
                 $this->_makeCover($docdir . 'html/t36-' . $infos['document_page'] . '.jpg');
@@ -1923,49 +1929,9 @@ class wsHTML5Compiler
             }
         }
 
-
-        //$this->makeThumbSprites($thumbs);
         $this->log('Made thumbnails');
     }
 
-//    public function makeThumbSprites(array $thumbs)
-//    {
-//        $cols = 10;
-//        $rows = 10;
-//        $perSprite = $cols * $rows;
-//        $k = 0;
-//        $res = '';
-//        $pages = count($thumbs);
-//
-//        $hash = '';
-//        for ($i = 1; $i <= $pages; $i += $perSprite) {
-//            $num = min(1 + $pages - $i, $perSprite);
-//            $srows = ceil($num / $cols);
-//            $files = array();
-//            $mtime = 0;
-//            for ($j = 0; $j < $perSprite; $j++) {
-//                $p = $i + $j;
-//                if ($p > $pages) {
-//                    break;
-//                }
-//                $files[] = $thumbs[$p];
-//                $hash .= $thumbs[$p] . '--' . filemtime($thumbs[$p]);
-//            }
-//
-//            $cache = WS_CACHE . '/thumbsprites/' . hash('sha256', $hash) . '.jpg';
-//            $dest = 'data/thumbnails/s' . $k . '.jpg';
-//            if (!file_exists($cache)) {
-//                $ratio = $this->width / $this->height;
-//                $thumbh = round(100 / $ratio);
-//                $cmd = 'montage ' . implode(' ', $files) . ' -geometry 100x' . $thumbh . '!+0+0 -background transparent -tile ' . $cols . 'x' . $srows . ' ' . $cache;
-//                $res .= `$cmd`;
-//            }
-//            $this->vdir->copy($cache, $dest);
-//            $k++;
-//        }
-//        return $res;
-//    }
-
     protected function _makeCover($orig)
     {
         $size = CubeIT_Image::getimagesize($orig);
@@ -2610,13 +2576,13 @@ class wsHTML5Compiler
             $lead = '';
             $image = '';
 
-            $first=true;
+            $first = true;
 
             foreach ($a->children() as $child) {
-                if($first){
-                    $first=false;
-                    if($child->getName()!=='category'){
-                        $inner.='<h3>&nbsp;</h3>';
+                if ($first) {
+                    $first = false;
+                    if ($child->getName() !== 'category') {
+                        $inner .= '<h3>&nbsp;</h3>';
                     }
                 }
                 $inner .= $this->_articleToHTML($child, $title, $lead, $image);