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