From 1a367344d6a0bd5782318bcad44488fae4441a1e Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 30 Sep 2009 16:51:02 +0000 Subject: [PATCH] --- inc/config.inc.php | 10 +-- inc/extranet/Controlleur/class.ws.flash.php | 3 +- inc/extranet/Metier/class.ws.document.php | 76 +++++++++++++++++++-- inc/prepend.php | 4 +- 4 files changed, 82 insertions(+), 11 deletions(-) diff --git a/inc/config.inc.php b/inc/config.inc.php index 45ec90aa2..c20d0f23f 100644 --- a/inc/config.inc.php +++ b/inc/config.inc.php @@ -11,7 +11,9 @@ if (in_array($_SERVER['HTTP_HOST'], array_merge($localrel, $localabs))) { define('DB_NAME', 'extranet'); define('DB_USER', 'root'); define('DB_PASSWORD', 'valparaiso'); - define('DEV',true); + define('DEV', true); + define('WINDOWS',true); + define('FONT_PATH', 'C:/Windows/Fonts'); if (in_array($_SERVER['HTTP_HOST'], $localrel)) { define('WEBROOT', '/cubeExtranet'); @@ -20,20 +22,18 @@ if (in_array($_SERVER['HTTP_HOST'], array_merge($localrel, $localabs))) { define('WEBROOT', ''); define('SITE_PATH', WEBROOT . '/'); } - - $tools = ROOT . '/../inc/tools/'; } else { // Définition des variables dans l'environnement de production define('DB_HOST', 'localhost'); define('DB_NAME', 'extranet'); define('DB_USER', 'ws'); define('DB_PASSWORD', 'atacama'); - define('WEBROOT', ''); define('SITE_PATH', WEBROOT . '/'); define('FTPROOT', '/usb/ftpextranet/'); - define('DEV',false); + define('DEV', false); + define('WINDOWS',false); } if (in_array($_SERVER['HTTP_HOST'], $ws)) { diff --git a/inc/extranet/Controlleur/class.ws.flash.php b/inc/extranet/Controlleur/class.ws.flash.php index a336d7a03..08aadb4c5 100644 --- a/inc/extranet/Controlleur/class.ws.flash.php +++ b/inc/extranet/Controlleur/class.ws.flash.php @@ -31,7 +31,8 @@ class wsFlash extends cubeFlashGateway { $document = $dao->sauve($data); $document->copyOriginal($infos['tmp_name']); $document->getInfos(); - $document->getTextes(); + $document->getTexts(); + $document->makeThumbs(); } $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 071a01836..4b73fff3e 100644 --- a/inc/extranet/Metier/class.ws.document.php +++ b/inc/extranet/Metier/class.ws.document.php @@ -13,6 +13,7 @@ class wsDocument extends cubeMetier { protected $log; protected $log_pointer; protected $infos; + protected $textes; protected $pages; @@ -40,12 +41,17 @@ class wsDocument extends cubeMetier { $pdfinfo->execute(); $this->addToLog($pdfinfo); - file_put_contents($this->infos, $pdfinfo->output); + $pdftk = new cubeCommandLine('pdftk', null, true); + $pdftk->setArg(null, $this->in); + $pdftk->setArg(null, 'dump_data'); + $pdftk->execute(); + $this->addToLog($pdftk); + + file_put_contents($this->infos, $pdfinfo->output . $pdftk->output); } public function getTexts() { - echo 'pdftotext'; $pdftotext = new cubeCommandLine('pdftotext', null, true); $pdftotext->setArg('q'); $pdftotext->setArg('f', 1); @@ -61,11 +67,73 @@ class wsDocument extends cubeMetier { public function makeThumbs() { + $this->makeShotPNM(); + } + + public function makeShotGS($resolution = 72, $quality = 90) + { + // Fabrication des thumbanails avec ghostscript + $gs = new cubeCommandLine('gs', null, true); + // $gs->setEnv('GS_FONTPATH', '/home/typo/fonts'); + $gs->setArg('-dBATCH'); + $gs->setArg('-dNOPAUSE'); + $gs->setArg('-dNOPROMPT'); + $gs->setArg('-sDEVICE=jpeg'); + $gs->setArg('-dUseCIEColor'); + $gs->setArg('-r' . $resolution); + $gs->setArg('-dJPEGQ=' . $quality); + // if (!$crop) { + // $gs->setArg('-dUseCropBox'); + // } + $gs->setArg('-sOutputFile=' . $this->out . '/te%d.jpg'); + $gs->setArg('-dAutoRotatePages=/None'); + $gs->setArg(null, $this->in); + $gs->execute(); + $this->addToLog($gs); } - public function addToLog($cl) + public function makeShotPNM($resolution = 72, $quality = 90) { - $c = '---' . "\n" . $cl->commande . "\n\n" . $cl->output . "\n--\n"; + // Exporte les fichiers + $pdftoppm = new cubeCommandLine('pdftoppm', null, true); + $pdftoppm->setArg('f', 1); + $pdftoppm->setArg('l', 10000); + + $pdftoppm->setArg('-freetype yes'); + $pdftoppm->setArg('-aa yes'); + $pdftoppm->setArg('-aaVector yes'); + if (!WINDOWS) { + $pdftoppm->setArg('-t1lib yes'); + } + $pdftoppm->setArg('r', $resolution); + $pdftoppm->setArg(null, $this->in); + $pdftoppm->setArg(null, $this->out . 'ppm'); + $pdftoppm->execute(); + $this->addToLog($pdftoppm); + + for($i = 1;true;$i++) { + $ppmfile = $this->out . 'ppm-' . cubeMath::fill($i, 6) . '.ppm'; + $jpegfile = $this->out . 'te' . $i . '.jpg'; + if (!file_exists($ppmfile)) { + break; + } + $pnmtojpeg = new cubeCommandLine('pnmtojpeg', $jpegfile, false); + $pnmtojpeg->setArg('-quality=' . $quality); + $pnmtojpeg->setArg('-density=' . $resolution . 'x' . $resolution . 'dpi'); + $pnmtojpeg->setManualArg($ppmfile); + $pnmtojpeg->execute(); + + $this->addToLog($pnmtojpeg, false); + }unlink($ppmfile); + } + } + + public function addToLog($cl, $output = true) + { + $c = '---' . "\n" . $cl->commande . "\n\n"; + if ($output) { + $cl->output . "\n\n"; + } fwrite($this->log_pointer, $c); } diff --git a/inc/prepend.php b/inc/prepend.php index 560eb7d67..3f64a7aa6 100644 --- a/inc/prepend.php +++ b/inc/prepend.php @@ -23,9 +23,11 @@ if (isset($_POST['q'])) { } if (DEV) { + $tools = ROOT . '/../inc/tools/'; cubePHP::appendEnv('PATH', $tools); cubePHP::appendEnv('PATH', $tools . 'gs8.70/bin/'); - cubePHP::appendEnv('PATH', $tools . 'gs8.70/lin/'); + cubePHP::appendEnv('PATH', $tools . 'gs8.70/lib/'); + cubePHP::setEnv('GS_FONTPATH', FONT_PATH); } ?> \ No newline at end of file -- 2.39.5