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);
}
}
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);
$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);
// $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);
}
}
// 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);
}
}
- 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);
* 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
$this->multiApp = $this->home = $home;
$this->version = $version;
+
if ($version == 'stable') {
$this->assets = WS_COMPILE_ASSETS . '/player/branches/master';
} else if ($version == 'dev') {
$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);
$this->scale = 1;
-
$this->numerotation = explode(',', $this->book->numerotation);
if ($this->isMobileFirst()) {
$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) {
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;
}
$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');
}
}
-
- //$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);
$lead = '';
$image = '';
- $first=true;
+ $first = true;
foreach ($a->children() as $child) {
- if($first){
- $first=false;
- if($child->getName()!=='category'){
- $inner.='<h3> </h3>';
+ if ($first) {
+ $first = false;
+ if ($child->getName() !== 'category') {
+ $inner .= '<h3> </h3>';
}
}
$inner .= $this->_articleToHTML($child, $title, $lead, $image);