Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3f5dccc

Browse files
authored
fix: Default x and y to 0 in ImageRenderer (#206)
Fixes#189
1 parentf6d501c commit3f5dccc

File tree

5 files changed

+52
-14
lines changed

5 files changed

+52
-14
lines changed

‎src/Rasterization/Renderers/ImageRenderer.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ public function render(SVGRasterizer $rasterizer, array $options, SVGNode $conte
2525
{
2626
$transform =$rasterizer->getCurrentTransform();
2727

28-
$x =$options['x'];
29-
$y =$options['y'];
28+
$x =$options['x'] ??0;
29+
$y =$options['y'] ??0;
3030
$transform->map($x,$y);
3131

32-
$width =$options['width'];
33-
$height =$options['height'];
32+
// TODO support "auto" values for width and height
33+
34+
$width =$options['width'] ??0;
35+
$height =$options['height'] ??0;
36+
if ($width <=0 ||$height <=0) {
37+
return;
38+
}
3439
$transform->resize($width,$height);
3540

3641
$image =$rasterizer->getImage();

‎tests/Rasterization/Renderers/ImageRendererTest.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespaceSVG;
44

5+
useAssertGD\GDSimilarityConstraint;
56
useSVG\Rasterization\Renderers\ImageRenderer;
67
useSVG\Nodes\SVGNode;
8+
useSVG\Rasterization\SVGRasterizer;
79

810
class SVGNodeClassextends SVGNode
911
{
@@ -27,17 +29,39 @@ class ImageRendererTest extends \PHPUnit\Framework\TestCase
2729
{
2830
publicfunctiontestRender()
2931
{
30-
$rast =new \SVG\Rasterization\SVGRasterizer(10,20,null,100,200);
31-
$options = [
32-
'href' =>__DIR__ .'/../../sample.svg',
33-
'x' =>10.5,
34-
'y' =>10.5,
35-
'width' =>100.5,
36-
'height' =>100.5
37-
];
38-
$svgImageRender =newImageRenderer();
32+
$obj =newImageRenderer();
33+
3934
$context =newSVGNodeClass();
4035

41-
$this->assertNull($svgImageRender->render($rast,$options,$context));
36+
$rasterizer =newSVGRasterizer(10,10,null,100,100);
37+
$obj->render($rasterizer, [
38+
'href' =>__DIR__ .'/../../squares.svg',
39+
'x' =>1,
40+
'y' =>2,
41+
'width' =>6,
42+
'height' =>6
43+
],$context);
44+
$img =$rasterizer->finish();
45+
46+
$this->assertThat($img,newGDSimilarityConstraint('./tests/images/renderer-image.png'));
47+
}
48+
49+
publicfunctiontestDefaultsXAndYToZero()
50+
{
51+
$obj =newImageRenderer();
52+
53+
$context =newSVGNodeClass();
54+
55+
$rasterizer =newSVGRasterizer('10px','10px',null,100,100);
56+
$obj->render($rasterizer, [
57+
'href' =>__DIR__ .'/../../squares.svg',
58+
'x' =>null,
59+
'y' =>null,
60+
'width' =>6,
61+
'height' =>6
62+
],$context);
63+
$img =$rasterizer->finish();
64+
65+
$this->assertThat($img,newGDSimilarityConstraint('./tests/images/renderer-image-x0y0.png'));
4266
}
4367
}

‎tests/images/renderer-image-x0y0.png

289 Bytes
Loading

‎tests/images/renderer-image.png

295 Bytes
Loading

‎tests/squares.svg

Lines changed: 9 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp