ImageMagick / ImageMagick

🧙‍♂️ ImageMagick 7
https://imagemagick.org
Other
12.2k stars 1.36k forks source link

SVG Density / Resolution doesn't work in MagickWand #63

Closed StalderT closed 8 years ago

StalderT commented 8 years ago

Hello,

I want to convert a svg file to png, with increasing resolution.

Using command line works :

convert -density 200 a.svg a.png

Using API doesn't work (convert works but only with original resolution) :

  MagickWandGenesis();
  magick_wand=NewMagickWand(); 
  status=MagickSetResolution(magick_wand,1000,1000);
  if (status == MagickFalse)
    ThrowWandException(magick_wand);
  status=MagickReadImage(magick_wand,argv[1]);
  if (status == MagickFalse)
    ThrowWandException(magick_wand);

  printf("width=%d, height=%d\n", MagickGetImageWidth(magick_wand),  MagickGetImageHeight(magick_wand));

  status = MagickResizeImage( magick_wand, 1000, 1000, LanczosFilter, 1.0);

  if ( status == MagickFalse )
    ThrowWandException(magick_wand);

  status=MagickWriteImages(magick_wand,argv[2],MagickTrue);
  if (status == MagickFalse)
    ThrowWandException(magick_wand);
  magick_wand=DestroyMagickWand(magick_wand);
  MagickWandTerminus();

MagickSetResolution(magick_wand,1000,1000) seem to have no effect (width and height not change even if we change resolution)

Thanks in advance

dlemstra commented 8 years ago

Which version of ImageMagick are you using?

StalderT commented 8 years ago

I use ImageMagick version 6.9.2-8 Q16

dlemstra commented 8 years ago

I get an image with a different width and height when I change the 1000 to 100 in the MagickSetResolution call. What is the output of: convert -list format | grep -i svg

StalderT commented 8 years ago

result :

     MSVG  rw+   ImageMagick's own SVG internal renderer
      SVG  rw+   Scalable Vector Graphics (XML 2.9.2)
     SVGZ  rw+   Compressed Scalable Vector Graphics (XML 2.9.2)

Here my svg file (renamed to txt) a.txt

Thanks in advance for all.

StalderT commented 8 years ago

I have test under cygwin with version : ImageMagick 6.9.1-3 Q16

$ convert -list format | grep -i svg
     MSVG  rw+   ImageMagick's own SVG internal renderer
      SVG  rw+   Scalable Vector Graphics (RSVG 2.40.9)
     SVGZ  rw+   Compressed Scalable Vector Graphics (RSVG 2.40.9)

And it works !

I don't now why API doesn't work on my linux and why convert utility works.

Regards,

dlemstra commented 8 years ago

It seems that under cygwin convert uses RSVG instead of MSVG (XML 2.9.2). The latter is not as good as RSVG and I would advise you to use librsvg in both situations.

StalderT commented 8 years ago

I understand RSVG is better than XML. But I don't understant why convert works with XML and API not.

dlemstra commented 8 years ago

I think the you don't have librsvg installed on your linux machine. And if cygwin uses the Windows installer this will include librsvg.

StalderT commented 8 years ago

No I don't have librsvg on my linux machine. But convert --density works on my linux machine without librsvg (API not).