Page 1 of 1

Imagemagick -density stopped working

Posted: 2012-05-13T16:56:41-07:00
by realmaverick
I have the latest version of imagemagick installed on my mac. Density has always worked fine.

However I recompiled with rsvg support and now density has no effect, regardless of where in the command it appears.

I have 500 SVG images that I need to convert to .png. They are currently converting at 48x48px.

I need them at 128x128 but cannot for the life of me get this working.

mogrify -density 1000 -background none -format png -resize 128x128 *svg

I'm typing via iPhone ATM so my syntax maybe slightly wrong. But even following the most basic commands to alter density fails. Also via the convert command.

Any ideas why adding rsvg has broken the density option?

Re: Imagemagick -density stopped working

Posted: 2012-05-14T05:57:28-07:00
by glennrp
How are you determining that the density is not working? What
version were you using previously that gave you the result you
wanted?

Previously the PNG encoder would encode the density in more
than one way (text and pHYs), if both were present in the
image properties. Now it only writes one of them, pHYs by
default. This change occurred in version 6.6.8-2. See this
ChangeLog entry:

* Don't write a PNG text chunk with "density" keyword that overrides the
PNG pHYs chunk, if the pHYs chunk was not excluded.

If you want the text "density" chunk and not the PNG pHYs chunk, you
can use "-define PNG:exclude-chunk=pHYs".

Re: Imagemagick -density stopped working

Posted: 2012-05-14T07:46:06-07:00
by realmaverick
How are you determining that the density is not working? What
version were you using previously that gave you the result you
wanted?
The fact the output is always 48x48 regardless of the density set.

Previously, I was using Imagemagick without the RSVG option. But when working with complex gradients, the result was terrible.

I had a pack of icons, that I ran the command on, it converted them all perfectly, minus the gradients. The density of the SVG was increased and the resulting png was perfect.

However, since recompiling with RSVG, the gradients are now perfect but the SVG density isn't increased. Regardless of the density set, I end up with a 48x48 png, which is pixel perfect.

However, if I -resize 128x128 I end up with a pixelated 128x128 png image. I believe this is because the -density 500 or whatever, is failing to work.

Ultimately, I need to make the SVG bigger, before it's converted to PNG to prevent pixelation. I added a 500x500 SVG in the mix and the result is perfect, a 128x128 png image, crisp and clear.

But these 48x48 are not working. Other than density, is there any option to make the SVG larger, prior to being converted to png?

Code: Select all

mogrify -density 300 -set units PixelsPerCentimeter -background none -format png -resize 128x128 *.svg
I have tried just density and the output is always 48x48 or if resize is used a blurry 128x128 icon.

Re: Imagemagick -density stopped working

Posted: 2012-05-14T10:36:02-07:00
by realmaverick
Tried uninstalling and reinstalling imagemagick but same issue.

I have read about 1,000 threads, trying to find a solution and I cannot find another being on the entire planet with this issue.

I could understand -density having no effect if I were doing it after the conversion to .png but as it's the first command it should work.

-geometry 128x128 works but makes the image blurry.

Nightmare :(

Re: Imagemagick -density stopped working

Posted: 2012-05-14T12:16:12-07:00
by fmw42
Does it happen with one image using convert? what version of IM? It is possible that mogrify is too primitive to know to apply -density before reading the svg file. (Just thinking out loud -- not sure of anything here)

Check

convert -list configure

and be sure you have rsvg in the line starting with DELEGATES.

Also what do you get from

convert -list format

Does it say?

SVG SVG rw+ Scalable Vector Graphics (RSVG 2.34.2)
SVGZ SVG rw+ Compressed Scalable Vector Graphics (RSVG 2.34.2)


And what version of RSVG?

What happens if you remove RSVG and just use IM's internal SVG?

Re: Imagemagick -density stopped working

Posted: 2012-05-14T13:08:15-07:00
by realmaverick
Hey, thanks for repsonding.

Yes is happens with both mogrify and convert, that was also my first thought.

Image magic version: ImageMagick @6.7.6-7_0+q16+rsvg

I am not entirely sure how to easily switch back to the built in SVG handling. I uninstalled (via a guide) the version of imagemagick without rsvg.

At first, prior to rsvg, density was working and the image was clear, but the gradients were wrong. Since reinstalling with RSVG support, density has failed to work at all.

I'm not sure how to find what version of RSVG I'm using. I installed via mac ports.

Typing convert -list format I see

Code: Select all

      SVG  SVG       rw+   Scalable Vector Graphics (RSVG 2.34.2)
     SVGZ  SVG       rw+   Compressed Scalable Vector Graphics (RSVG 2.34.2)
I hope that answers the questions. Thanks again.

Re: Imagemagick -density stopped working

Posted: 2012-05-14T14:02:36-07:00
by fmw42
Can you post a link to one of your svg files that fails? I can test on my system. It could be an IM version problem.

Re: Imagemagick -density stopped working

Posted: 2012-05-22T14:42:52-07:00
by adiabatic
I'm having the same problem as the OP.

Code: Select all

$ convert -list configure | grep "DELEGATES.*rsvg"
DELEGATES     bzlib fontconfig freetype gs jpeg jng lcms2 lzma png rsvg tiff x11 xml zlib

Code: Select all

$ convert -list format | grep SVG
     MSVG  SVG       rw+   ImageMagick's own SVG internal renderer
      SVG  SVG       rw+   Scalable Vector Graphics (RSVG 2.34.2)
     SVGZ  SVG       rw+   Compressed Scalable Vector Graphics (RSVG 2.34.2)
Don't know how to remove RSVG. Last I tried ImageMagick without it, it failed to do something I needed — CSS-in-SVG, I think.

Code: Select all

$ convert --version
Version: ImageMagick 6.7.6-9 2012-05-18 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features:  OpenCL   
Installed via MacPorts.

Sample image available at http://dl.dropbox.com/…/googly-fitocracy.svg.

Converted with:

Code: Select all

convert -density 288 -background none googly-fitocracy.svg googly-fitocracy.png

Re: Imagemagick -density stopped working

Posted: 2012-05-22T16:19:16-07:00
by fmw42
Works fine for me with IM 6.7.7.0 Q16 Mac OSX Snow Leopard. What version of IM are you using?


convert -density 288 -background none googly-fitocracy.svg googly-fitocracy.png
identify -verboe googly-fitocracy.png
Image: googly-fitocracy.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 360x360+0+0
Resolution: 288x288
Print size: 1.25x1.25
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit

Though you probably should set the units to pixelspercentimeter (as that is all png supports as far as I know). If you need 288 pixels per inch, then convert 288 to 288*2.54=732

convert -density 732 -units pixelspercentimeter -background none googly-fitocracy.svg googly-fitocracy.png
identify -verbose googly-fitocracy.png

Image: googly-fitocracy.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 360x360+0+0
Resolution: 732x732
Print size: 1.25x1.25
Units: PixelsPerCentimeter
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit

Re: Imagemagick -density stopped working

Posted: 2012-05-23T14:49:22-07:00
by adiabatic
Thanks for the help!

My results match yours, but as far as I can tell, `convert -density 144 foo.svg foo.png`, where foo.svg is nominally 360 px by 360 px, used to give me a nice, sharp image with geometry of 720x720 pixels. (I've ran `identify -verbose googly-github.png` to check). What options should I be passing to convert to get what I want? Like the OP, both -geometry and -resize give me images with the geometry I want, but they're blurry as if they were enlarged from a 360x360 bitmap instead of being rendered at 720x720.

Would it help if I posted SVGs and PNGs of the other images for comparison?

Re: Imagemagick -density stopped working

Posted: 2012-05-23T14:54:16-07:00
by fmw42
Would it help if I posted SVGs and PNGs of the other images for comparison?
Yes one example of the problem and the exact commands used to create it should suffice.

But this works fine for me on IM 6.7.7.0 Q16 Mac OSX Snow Leopard:


convert -density 144 googly-fitocracy.svg googly-fitocracy.png
identify -verbose googly-fitocracy.png
Image: googly-fitocracy.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 360x360+0+0
Resolution: 144x144
Print size: 2.5x2.5
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB

Image

Re: Imagemagick -density stopped working

Posted: 2012-05-23T15:22:51-07:00
by adiabatic
I used:

Code: Select all

convert -density 144 -background none googly-facebook.svg googly-facebook.png
Under the old ImageMagick (whatever version I was using on March 20, 2012), that gave me this image:

Image

Now, it gives me this, which is not what I want:

Image

If you'd like to test this yourself, the source SVG is at http://dl.dropbox.com/…/googly-facebook.svg.

Re: Imagemagick -density stopped working

Posted: 2012-05-23T15:30:12-07:00
by fmw42
Your old image is not 360x360 pixels, but larger by 2x, so you must have used a larger density, namely 288x288. I get the same size as you do currently. Testing...


convert -density 288 googly-fitocracy.svg googly-fitocracy2.png
identify -verbose googly-fitocracy2.png
Image: googly-fitocracy2.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 360x360+0+0
Resolution: 288x288
Print size: 1.25x1.25
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB

So it would look like the image size is not changing by changing the density, which is what I thought happens with vector to raster conversion. But I am no expert on SVG format. Perhaps there is something in the file that specifies the images size. If that is the case, then only the density would change.

cat googly-fitocracy.svg

<svg viewBox='-180 -180 360 360' width='360' height='360' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>
...

So it does look like the image size is fixed in the svg file to 360x360. Thus I would expect that setting the density would only change the density, so that the size is only affected by printing.

It would appear that if there was a bug, it was with the older version. What older version were you using?

Testing under IM 6.7.4.10, I can confirm that the image does get expanded to 720x720. But I cannot say which is correct. So I would report this difference on the Bugs forum and see what they say. Please show the commands used and if possible the two different results from the two IM versions. Also point a link back to this discussion. But repeat the important commands and example images there.

P.S. My tests were all done using RSVG as my delegate for svg in both versions of IM