I have a batch of SVG images that I need to resize and then save as PNG, and I'd like to use PHP to do it. Similar questions to mine have been asked but none of the solutions work for me. For example:
option A: use PHP to change the width and height attribute of the SVG.
problem with A: this seems to work fine but in fact it only increases the canvas size, not the contents of the canvas. I'm not sure if it's important but my SVGs are small graphics that were created with Illustrator, mostly made up of path elements.
option B: use imagick to resize and resave
example:
$im = new Imagick();
$im->setResolution( $startResolution * ($newWidth / $oldWidth ), $startResolution * ($newHeight / $oldHeight ) );
$im->readImage( $svgSource );
$im->setImageFormat("png32");
echo '<img src="data:image/png;base64,' . base64_encode($im) . '" />';
problem with B: this also seems to work fine but the resulting png will be blurry
option C: variant of option B, you set the resolution really high, like 5000, then resize.
problem with C: the resulting PNG is still blurry
option D: use exec(convert...) to get around PHP's bugs
problem with D: you guessed it, the resulting PNG is still blurry
Has anyone found a way to make this work?