Page 1 of 1

Resize SVG and convert to PNG without losing quality

Posted: 2008-08-20T15:21:26-07:00
by Znupi
I have discussed this with Mikko but haven't reached a conclusion. Please read the comments here: http://valokuva.org/?p=102#comment-5777 to get a picture of what I'm trying to achieve. I would post the question here again, but we already discussed some possible solutions there so I think it's better if you read those comments. Thanks.

Re: Resize SVG and convert to PNG without losing quality

Posted: 2008-08-22T05:13:01-07:00
by Znupi
Bump :-( can anyone help?

Re: Resize SVG and convert to PNG without losing quality

Posted: 2008-08-22T08:12:54-07:00
by el_supremo
[edit] scratch that. It looks like you've tried it.
I'm not sure of all you're trying to do but I'm pretty sure you should be setting the resolution, not the units, with a number like 1000.
The units are things like pixelsperinch or pixelspercentimeter, whereas the resolution is a number.

Pete

Re: Resize SVG and convert to PNG without losing quality

Posted: 2008-08-22T09:04:00-07:00
by el_supremo
Can you post the svg file you're using?

Pete

Re: Resize SVG and convert to PNG without losing quality

Posted: 2008-08-22T13:13:36-07:00
by Znupi
Sure, here it is: http://znupi.ath.cx/files/s2w1.svg (my server serves it as plain text for some reason.. anyway, my server doesn't have Imagick, my desktop does)
Say I want to resize it to 600x400 (its nominal size is 300x200), how would I do that? Thanks for the reply :-)

Re: Resize SVG and convert to PNG without losing quality

Posted: 2008-08-23T04:41:40-07:00
by Znupi
I've done it! Yay! I was expecting it to be something like this, but I didn't know all the Imagick functions and etcetera. After some testing and fiddling around, here's what I came up with:

Code: Select all

$im = new Imagick();
$im->readImage("s2w1.svg");
$res = $im->getImageResolution();
$x_ratio = $res['x'] / $im->getImageWidth();
$y_ratio = $res['y'] / $im->getImageHeight();
$im->removeImage(); // Remove the image because setResolution has to be called before readImage because the image gets rasterized after that, and setResolution has no effect.
$im->setResolution(900 * $x_ratio, 600 * $y_ratio); // this resizes the image to 900x600 pixels! Yay!! No loss of quality!!!
$im->readImage("s2w1.svg");
// Now you can convert to PNG or do whatever you want
If anyone needs this I hope they come across this thread. Or if someone knows a better way, I hope they come across this thread, too :P