protected $trim;\r
protected $date;\r
protected $localInfos;\r
+ protected $generalInfos;\r
\r
protected $out;\r
protected $in;\r
$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
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
$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
$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
$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
$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
\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