]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 9 Oct 2009 12:31:08 +0000 (12:31 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 9 Oct 2009 12:31:08 +0000 (12:31 +0000)
inc/extranet/Controlleur/class.ws.flash.php
inc/extranet/Metier/class.ws.document.php

index 08aadb4c513249af4dbe743c2096c74f0f3c01e4..8cffb86288f9e19a66cffffdaa51d82f91c7edf5 100644 (file)
@@ -32,7 +32,7 @@ class wsFlash extends cubeFlashGateway {
                        $document->copyOriginal($infos['tmp_name']);\r
                        $document->getInfos();\r
                        $document->getTexts();\r
-                       $document->makeThumbs();\r
+                       $document->makeMiniThumbs();\r
                }\r
                $this->xml->addChild('document_id', $document->document_id);\r
        }\r
index 0aeeefab32565acfa09b6d974339710ce68388fe..d9c2b33993d7beaa96124bdb3a5635b1179a1a24 100644 (file)
@@ -7,6 +7,7 @@ class wsDocument extends cubeMetier {
        protected $trim;\r
        protected $date;\r
        protected $localInfos;\r
+       protected $generalInfos;\r
 \r
        protected $out;\r
        protected $in;\r
@@ -45,7 +46,7 @@ class wsDocument extends cubeMetier {
                $pdftk->execute();\r
                $this->addToLog($pdftk);\r
 \r
-               $docInfos = $this->parseInfos($pdfinfo->output . $pdftk->output);\r
+               $this->generalInfos = $this->parseInfos($pdfinfo->output . $pdftk->output);\r
 \r
                file_put_contents($this->infos, $pdfinfo->output . $pdftk->output);\r
        }\r
@@ -53,6 +54,7 @@ class wsDocument extends cubeMetier {
        public function parseInfos($data)\r
        {\r
                $res = array();\r
+               $res['size'] = array(0, 0);\r
                $lines = explode("\n", $data);\r
                foreach($lines as $line) {\r
                        $line = trim(cubeText::condenseWhite($line));\r
@@ -65,6 +67,8 @@ class wsDocument extends cubeMetier {
                                $res['page'][$m[1]][strtolower($m[2])] = array($m[3], $m[4], $m[5], $m[6]);\r
                        } elseif (preg_match('|Page ([0-9]+) size: ([0-9.]*)([\sx]+)([0-9.]*)(.*)|iu', $line, $m)) {\r
                                $res['page'][$m[1]]['size'] = array($m[2], $m[4]);\r
+                               $res['size'][0] = max($res['size'][0], $m[2]);\r
+                               $res['size'][1] = max($res['size'][1], $m[4]);\r
                        }\r
                }\r
 \r
@@ -78,7 +82,6 @@ class wsDocument extends cubeMetier {
                $pdftotext->setArg('f', 1);\r
                $pdftotext->setArg('l', 10000);\r
                $pdftotext->setArg('-eol', 'unix');\r
-               // $pdftotext->setArg('-nopgbrk');\r
                $pdftotext->setArg('-enc', 'UTF-8');\r
                $pdftotext->setArg(null, $this->in);\r
                $pdftotext->setArg(null, $this->textes);\r
@@ -86,12 +89,66 @@ class wsDocument extends cubeMetier {
                $this->addToLog($pdftotext);\r
        }\r
 \r
-       public function makeThumbs()\r
+       public function makeMiniShot()\r
        {\r
-               $this->makeShotGS(300);\r
+               $this->makeShotFixedWidth('p', 100);\r
        }\r
 \r
-       public function makeShotGS($resolution = 72, $quality = 90, $antialiasing = 4)\r
+       public function makeRealShot()\r
+       {\r
+               $this->makeShot('te', 72);\r
+       }\r
+\r
+       public function makeShotFixedWidth($prefix, $w, $quality = 90, $antialiasing = 4)\r
+       {\r
+               // Make thumbs of $w width\r
+               // resolution 72 make 1pt=1px\r
+               $width = $this->generalInfos['size'][0];\r
+               $ratio = $width / $w;\r
+               $this->makeShotGS($prefix, round(72 / $ratio), $quality, $antialiasing);\r
+       }\r
+\r
+       public function makeShotFixedHeight($prefix, $h, $quality = 90, $antialiasing = 4)\r
+       {\r
+               // Make thumbs of $w height\r
+               // resolution 72 make 1pt=1px\r
+               $height = $this->generalInfos['size'][1];\r
+               $ratio = $height / $h;\r
+               $this->makeShotGS($prefix, round(72 / $ratio), $quality, $antialiasing);\r
+       }\r
+\r
+       public function makeShot($prefix, $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'GS')\r
+       {\r
+               // Delete all old files\r
+               for($i = 1;$i <= $this->generalInfos['pages'];$i++) {\r
+                       if (file_exists($this->out . $prefix . $i . '.jpg')) {\r
+                               @unlink($this->out . $prefix . $i . '.jpg');\r
+                       }\r
+               }\r
+               if ($method == 'GS') {\r
+                       $this->makeShotGS($prefix, $resolution, $quality, $antialiasing);\r
+               } elseif ($method == 'PNM') {\r
+                       $this->makeShotPNM($prefix, $resolution, $quality, $antialiasing);\r
+               }\r
+               // Test the result by checking all files\r
+               $error = false;\r
+               for($i = 1;$i <= $this->generalInfos['pages'];$i++) {\r
+                       if (!file_exists($this->out . $prefix . $i . '.jpg')) {\r
+                               $error = true;\r
+                               break;\r
+                       }\r
+               }\r
+               // If error, we try to make thumbs with other method\r
+               if ($error) {\r
+                       if ($method == 'GS') {\r
+                               $this->makeShotPNM($prefix, $resolution, $quality, $antialiasing);\r
+                       } elseif ($method == 'PNM') {\r
+                               $this->makeShotGS($prefix, $resolution, $quality, $antialiasing);\r
+                       }\r
+               }\r
+       }\r
+\r
+       protected function makeShotGS($prefix, $resolution = 72, $quality = 90, $antialiasing = 4)\r
        {\r
                // Fabrication des thumbanails avec ghostscript\r
                $gs = new cubeCommandLine('gs', null, true);\r
@@ -105,27 +162,25 @@ class wsDocument extends cubeMetier {
                $gs->setArg('-dJPEGQ=' . $quality);\r
                $gs->setArg('-dTextAlphaBits=' . $antialiasing);\r
                $gs->setArg('-dGraphicsAlphaBits=' . $antialiasing);\r
-               // if (!$crop) {\r
-               // $gs->setArg('-dUseCropBox');\r
-               // }\r
-               $gs->setArg('-sOutputFile=' . $this->out . '/te%d.jpg');\r
+               $gs->setArg('-dUseCropBox');\r
+               $gs->setArg('-sOutputFile=' . $this->out . '/' . $prefix . '%d.jpg');\r
                $gs->setArg('-dAutoRotatePages=/None');\r
                $gs->setArg(null, $this->in);\r
                $gs->execute();\r
                $this->addToLog($gs);\r
        }\r
 \r
-       public function makeShotPNM($resolution = 72, $quality = 90, $antialiasing = 4)\r
+       protected function makeShotPNM($prefix, $resolution = 72, $quality = 90, $antialiasing = 4)\r
        {\r
-               $antialiasing=$antialiasing?'yes':'no';\r
+               $antialiasing = $antialiasing?'yes':'no';\r
                // Exporte les fichiers\r
                $pdftoppm = new cubeCommandLine('pdftoppm', null, true);\r
                $pdftoppm->setArg('f', 1);\r
                $pdftoppm->setArg('l', 10000);\r
 \r
                $pdftoppm->setArg('-freetype yes');\r
-               $pdftoppm->setArg('-aa '.$antialiasing);\r
-               $pdftoppm->setArg('-aaVector '.$antialiasing);\r
+               $pdftoppm->setArg('-aa ' . $antialiasing);\r
+               $pdftoppm->setArg('-aaVector ' . $antialiasing);\r
                if (!WINDOWS) {\r
                        $pdftoppm->setArg('-t1lib yes');\r
                }\r
@@ -137,7 +192,7 @@ class wsDocument extends cubeMetier {
 \r
                for($i = 1;true;$i++) {\r
                        $ppmfile = $this->out . 'ppm-' . cubeMath::fill($i, 6) . '.ppm';\r
-                       $jpegfile = $this->out . 'te' . $i . '.jpg';\r
+                       $jpegfile = $this->out . $prefix . $i . '.jpg';\r
                        if (!file_exists($ppmfile)) {\r
                                break;\r
                        }\r