Skip to content

Commit ea53155

Browse files
committed
Fix SVG embedded raster images
1 parent 65c2108 commit ea53155

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.2.0
1+
8.2.1

examples/images/testsvg.svg

Lines changed: 7 additions & 0 deletions
Loading

src/Base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ abstract class Base
183183
/**
184184
* TCPDF version.
185185
*/
186-
protected string $version = '8.2.0';
186+
protected string $version = '8.2.1';
187187

188188
/**
189189
* Time is seconds since EPOCH when the document was created.

src/SVG.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,13 @@
384384
* 'defsmode': bool,
385385
* 'clipmode': bool,
386386
* 'clipid': int,
387-
* 'gradientid': string,
388387
* 'tagdepth': int,
389388
* 'x0': float,
390389
* 'y0': float,
391390
* 'x': float,
392391
* 'y': float,
393392
* 'refunitval': TRefUnitValues,
393+
* 'gradientid': string,
394394
* 'gradients': array<string, TSVGGradient>,
395395
* 'clippaths': array<string, TSVGAttribs>,
396396
* 'defs': array<string, TSVGAttribs>,
@@ -399,6 +399,7 @@
399399
* 'child': array<int>,
400400
* 'textmode': TSVGTextMode,
401401
* 'text': string,
402+
* 'dir': string,
402403
* 'out': string,
403404
* }
404405
*
@@ -612,13 +613,13 @@ abstract class SVG extends \Com\Tecnick\Pdf\Text
612613
'defsmode' => false,
613614
'clipmode' => false,
614615
'clipid' => 0,
615-
'gradientid' => '',
616616
'tagdepth' => 0,
617617
'x0' => 0.0,
618618
'y0' => 0.0,
619619
'x' => 0.0,
620620
'y' => 0.0,
621621
'refunitval' => self::REFUNITVAL,
622+
'gradientid' => '',
622623
'gradients' => [],
623624
'clippaths' => [],
624625
'cliptm' => self::TMXID,
@@ -632,6 +633,7 @@ abstract class SVG extends \Com\Tecnick\Pdf\Text
632633
'text-anchor' => 'start',
633634
],
634635
'text' => '',
636+
'dir' => '',
635637
'out' => '',
636638
];
637639

@@ -3556,14 +3558,20 @@ protected function parseSVGTagSTARTimage(
35563558
// embedded image encoded as base64
35573559
$img = '@' . base64_decode(substr($img, strlen($match[0])));
35583560
}
3561+
3562+
if (!empty($this->svgobjs[$soid]['dir']) && (($img[0] == '.') || (basename($img) == $img))) {
3563+
// replace relative path with full server path
3564+
$img = $this->svgobjs[$soid]['dir'] . '/' . $img;
3565+
}
3566+
35593567
$imgid = $this->image->add($img);
35603568
$out .= $this->image->getSetImage(
35613569
$imgid,
35623570
$posx,
35633571
$posy,
35643572
$width,
35653573
$height,
3566-
$this->page->getPage()['pheight'],
3574+
$this->page->getPage()['height'],
35673575
);
35683576
$out .= $this->graph->getStopTransform();
35693577
return $out;
@@ -3872,6 +3880,11 @@ public function addSVG(
38723880
}
38733881
$this->graph->setPageHeight($pageheight);
38743882

3883+
$imgdir = dirname($img);
3884+
if ($imgdir === '.') {
3885+
$imgdir = '';
3886+
}
3887+
38753888
$data = $this->getRawSVGData($img);
38763889
if (empty($data)) {
38773890
throw new PdfException('Invalid SVG');
@@ -3969,6 +3982,7 @@ public function addSVG(
39693982

39703983
// @phpstan-ignore assign.propertyType
39713984
$this->svgobjs[$soid] = self::SVGDEFOBJ;
3985+
$this->svgobjs[$soid]['dir'] = $imgdir;
39723986
$this->svgobjs[$soid]['refunitval']['page']['height'] = $this->toPoints($pageheight);
39733987

39743988
$out = '';

0 commit comments

Comments
 (0)