public function getURL() {
$attributes = $this->getZoomAttributes();
if (!$this->rightClone) {
- ZoomLink::generateImage($attributes, $this->compiler, 'downloadportion', 'downloadportion');
+ ZoomLink::generateImage($attributes, $this->compiler, 'downloadportion', 'downloadportion', true);
}
return 'data/links/downloadportion_' . $attributes['id'] . '.jpg';
}
$pdf = $this->compiler->getWorkingDir() . '/' . $pdf;
}
- $res = [
+ $x = $this->left;
+ $y = $this->top;
+ $w = $this->width;
+ $h = $this->height;
+
+
+ if ($x < 0) {
+ $w -= $x;
+ $x = 0;
+ }
+ if ($y < 0) {
+ $h -= $y;
+ $y = 0;
+ }
+
+ $maxWidth = $this->compiler->getWidthForLinks();
+
+ if ($this->page % 2 === 0 && !$this->compiler->isOnePage()) {
+ $maxWidth *= 2;
+ }
+ $maxHeight = $this->compiler->getHeightForLinks();
+
+ if ($x + $w > $maxWidth) {
+ $w -= ($x + $w - $maxWidth);
+ }
+ if ($y + $h > $maxHeight) {
+ $h -= ($y + $h - $maxHeight);
+ }
+
+ return [
'id' => $this->id,
'page' => $this->page,
'maxzoom' => $this->compiler->getSetting('downloadPortionZoom', '8'),
'group' => '',
'group-count' => 0,
- 'width' => round($this->width),
- 'height' => round($this->height),
- 'x' => round($this->left),
- 'y' => round($this->top),
+ 'width' => round($w),
+ 'height' => round($h),
+ 'x' => round($x),
+ 'y' => round($y),
'pdf' => $pdf,
'border' => $this->border,
'borderColor' => $this->borderColor,
];
- return $res;
}
public function getAdditionnalContent() {
namespace Fluidbook\Tools\Links;
use Cubist\Util\CommandLine\Imagemagick;
-use Cubist\Util\Files\Files;
use Cubist\Util\Graphics\PDF;
use Cubist\Util\Text;
-use Fluidbook\Tools\Compiler\Compiler;
use Fluidbook\Tools\Compiler\CompilerInterface;
class ZoomLink extends NormalLink {
* @param $save
* @return void
*/
- public static function generateImage($attributes, $compiler, $cachedir, $save) {
+ public static function generateImage($attributes, $compiler, $cachedir, $save, $trim = false) {
$maxzoom = $attributes['maxzoom']; // Max zoom level might not always be set in the link editor
$maxzoom = max(2, min($maxzoom, 20));
$both = $leftfile;
}
+ if ($trim) {
+ $trimmed = str_replace('.jpg', '.trim.jpg', $both);
+ if (!file_exists($trimmed) || filemtime($trimmed) < filemtime($both)) {
+ Imagemagick::trim($both, $trimmed);
+ }
+ $both = $trimmed;
+ }
+
// if (isset($attributes['border']) && $attributes['border'] > 0) {
// $tmp = Files::tempnam() . '.jpg';
// Imagemagick::addBorder($both, $tmp, $attributes['border'], $attributes['borderColor']);