return false;
}
- public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
+ public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false)
{
if ($format === 'jpeg') {
$format = 'jpg';
$do = true;
} else if (isset($reffile) && filemtime($file) < filemtime($reffile)) {
$do = true;
+ } else if ($format === 'svg') {
+ $t = filemtime($file);
+ $do = $t < 1603181003 && $t > 1602662603;
}
- if ($do) {
+ if ($do || $force) {
$this->makeFile($file, $page, $format, $resolution, $withText, $withGraphics, $version);
}
return $file;
if ($force) {
$this->addToLog('Processing page #' . $page);
// Thumb for composition panel
- $this->makeMiniShot($page);
+ $this->getFile($page, 'jpg', 'thumb', true, true, '', true);
// Image for link editor
- $this->getFile($page,'swf');
+ $this->getFile($page, 'swf', 150, true, true, '', true);
// Make SVG base file
- $this->makeSVGFile($page, false);
+ $this->makeSVGFile($page, true);
}
}
$cmd = "timeout -s 1 120 /usr/local/bin/svgcleaner --allow-bigger-file --paths-coordinates-precision 3 --copy-on-error --stdout $in";
$svg = `$cmd`;
if ($svg == '') {
- copy($in, $out);
- return;
+ $svg = file_get_contents($in);
}
+ $svg = self::_disablePreserveRatio($svg);
file_put_contents($out, $svg);
}
+ protected static function _disablePreserveRatio($in)
+ {
+ $str = 'preserveAspectRatio="none"';
+ if (strpos($in, $str) !== false) {
+ return $in;
+ }
+ return str_replace("<svg ", '<svg ' . $str . ' ', $in);
+ }
+
public static function optimizeSVGImages($in, $out, $resolution)
{
$svg = file_get_contents($in);
$svg = preg_replace('/\<\?xml([^\?]*)\?\>/', '', $svg);
- $svg = substr_replace($svg, ' preserveAspectRatio="none" ', 5, 0);
+ $svg = self::_disablePreserveRatio($svg);
$osvg = preg_replace_callback('|\<image([^>]*)\>|', function ($matches) use ($resolution) {
return wsTools::optimizeRaster($matches, $resolution);