Page 1 of 1

convert -density XXX foo.svg foo.png: geometry unchanged

Posted: 2012-05-23T15:55:45-07:00
by adiabatic
-density doesn't change the image geometry anymore, which means I can't use ImageMagick to make large PNGs from SVGs without getting blurry images.

I occasionally use ImageMagick in a script to generate PNGs from SVGs. Here's a sample command:

Code: Select all

convert -density 144 -background none googly-facebook.svg googly-facebook.png
An old version of convert, run on March 20, 2012, gave me this image:

Image

The `-density 144` doubles the size while keeping the image nice and crisp. Here's what identify tells me about it:

Code: Select all

$ identify -verbose googly-facebook-old.png 
Image: googly-facebook-old.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 720x720+0+0
  Resolution: 144x144
  Print size: 5x5
Now, using the same arguments to convert (ImageMagick 6.7.7-0 from MacPorts on OS X 10.7.4), I get this:

Image

And here's identify, showing the unchanged geometry:

Code: Select all

$ identify -verbose googly-facebook-new.png 
Image: googly-facebook-new.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 360x360+0+0
  Resolution: 144x144
  Print size: 2.5x2.5
If you'd like to test this yourself, the source SVG is at http://dl.dropbox.com/…/googly-facebook.svg.

Re: convert -density XXX foo.svg foo.png: geometry unchanged

Posted: 2012-05-23T17:31:20-07:00
by magick
We can reproduce the problem you posted and have a patch. Look for it in ImageMagick 6.7.7-1 Beta by sometime tomorrow. Thanks.

Re: convert -density XXX foo.svg foo.png: geometry unchanged

Posted: 2012-05-24T11:31:01-07:00
by adiabatic
Wow, that was fast. Thanks!

Re: convert -density XXX foo.svg foo.png: geometry unchanged

Posted: 2012-06-07T12:39:19-07:00
by adiabatic
Confirmed that it works once again on OS X, using 6.7.7-2_0+q16+rsvg.

Thanks!

Re: convert -density XXX foo.svg foo.png: geometry unchanged

Posted: 2012-06-12T16:02:35-07:00
by utilmind
I having the same problem. Density does not working in ImageMagick 6.7.7-7 2012-06-13 Q16.
I'm am new in ImageMagick and installed it today the first time. Previously I had on my server installed very old version of 2006 (something like 6.2.XXX), but removed it already. However I saw that density has worked with that old release.

Could someone confirm please, whether -density parameter working already in 6.7.7-7? Maybe I doing something wrong?

Re: convert -density XXX foo.svg foo.png: geometry unchanged

Posted: 2012-06-12T16:27:57-07:00
by fmw42
This works fine for me under IM 6.7.7.7 Q16 Mac OSX Snow Leopard


convert -density 144 -background none googly-facebook.svg googly-facebook.png

identify -verbose googly-facebook.png
Image: googly-facebook.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 720x720+0+0
Resolution: 144x144
Print size: 5x5
Units: Undefined

Re: convert -density XXX foo.svg foo.png: geometry unchanged

Posted: 2012-06-12T16:44:13-07:00
by utilmind
Oops.. yes, you are right. The "resolution" parameter is really changed. I thought that -density parameter should resize the image as it was in old versions of ImageMagick.

So, accordingly to "identify" tool, it looks like "density" is really working, but then it's definitely not that parameter which I need to convert verctor image to static with specified width/height...

Re: convert -density XXX foo.svg foo.png: geometry unchanged

Posted: 2012-06-12T16:58:04-07:00
by fmw42
utilmind wrote:Oops.. yes, you are right. The "resolution" parameter is really changed. I thought that -density parameter should resize the image as it was in old versions of ImageMagick.
You are thinking of -resample. It changes density and resizes. see http://www.imagemagick.org/script/comma ... 7#resample

Re: convert -density XXX foo.svg foo.png: geometry unchanged

Posted: 2012-06-12T18:36:38-07:00
by utilmind
Thanks for reply! I have tried resample, density, resize, units and various of their combinations, but unfortunately it looks like SVG always appears "rasterized" before resizing.

I have reinstalled old version of ImageMagick (6.2.8) and tried again, just specifying density and it works as I need.

The image which I want to convert to PNG with specified size is http://www.favor.com.ua/stuff/test.svg

Here is what I running on OLD version to produce png:

Code: Select all

convert -density 144 test.svg test.png
it produces PNG with double size of SVG image (it still okay, I can convert dpi's to pixels and calculate size)
Result is perfect, it really produced PNG from vector image: http://www.favor.com.ua/stuff/test-old.png

Here is what I runing on NEW version to produce png:

Code: Select all

convert -density 144 test.svg test.png
Does nothing at all. At least visually. However I can see with "identify" that something changed in PNG's internal settings.
Result: http://www.favor.com.ua/stuff/test-new-density.png

And another try with -resample option:

Code: Select all

convert -resample 200x200 test.svg test.png
Result: http://www.favor.com.ua/stuff/test-new.png -- this image doesn't looks neither converted from vector image nor 200x200

Thanks a lot for any help or links to manuals!

Re: convert -density XXX foo.svg foo.png: geometry unchanged

Posted: 2012-06-12T19:12:18-07:00
by fmw42
You would likely need to put -resample after the input. But then it probably won't work on svg or other vector files as desired.

convert -density 144 test.svg test.png

I displayed the svg and png files in my browser and the png file was twice the size of the logo.svg. Is that what you expect?

This sounds like a problem that was recently fixed, though I cannot find the post on it. But you can search the archives.

My system is using RSVG delegate to handle the svg file.

SVG SVG rw+ Scalable Vector Graphics (RSVG 2.34.2)


You can try to install that. Or if you already have it and it does not work right, then try

convert -density 144 MSVG:logo.svg logo_tmp.png


But I suspect that it is your version of IM. Try upgrading. You never said what version you are using besides the very old one at 6.2.8 which is almost 500 versions old.

Re: convert -density XXX foo.svg foo.png: geometry unchanged

Posted: 2012-06-14T10:33:24-07:00
by utilmind
Thanks for your reply fmw42!

Yes, it seems that -density does not actually scale image because I didn't have RSVG installed. Unfortunately I still unable to install it for v.6.7.7, so I using v6.2.8 which perfectly installed together with RSVG library with "yum" command (I have CentOS on server).

So, currently I have actually 2 versions installed, v.6.7.7 in /usr/local/bin/ and v6.2.8 with RSVG in /usr/bin/...
I wish I can install/upgrade to latest version of ImageMagick + RSVG with "yum"... :? But currently I decided to use old version, it's okay for me, since all I need is to scale just one SVG image to raster PNG with specified width/height.