Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected result when rasterizing svg image that include style. #127

Open
roipoussiere opened this issue Jun 22, 2021 · 0 comments
Open
Labels
bug Something isn't working

Comments

@roipoussiere
Copy link

roipoussiere commented Jun 22, 2021

I try to output a png image from a svg but I get unexpected behavior with the style I use.

PHP code sample

<?php
require_once ("./vendor/autoload.php");

use SVG\SVG;

$image = SVG::fromFile('./test.svg');

$doc = $image->getDocument();
$raster = $image->toRasterImage($doc->getWidth(), $doc->getHeight());
imagepng($raster);

input SVG source

<svg height="100" width="200">
	<style>
rect { fill: red; }
circle { fill: darkgray; }
.container circle { fill: green; }
.container rect { fill: blue; }
	</style>

	<circle cx="50" cy="50" r="40"/>
	<rect x="30" y="30" width="40" height="40"/>
	<g class="container">
		<circle cx="150" cy="50" r="40"/>
		<rect x="130" y="30" width="40" height="40"/>
	</g>
</svg>

Input SVG image

image

Output PNG image

image

Observations

  • the style defined directly on svg elements is not used;
  • the style defined for an element in a container is used by the whole container.
@meyfa meyfa added the bug Something isn't working label Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants