3

When using the following code to convert an SVG to a PNG file, the text looks terrible. The image is not scaled, so I have no idea why the quality of the text is so bad.

Additionally, although it is hard to see, the text in the PNG seems to be some serif font, while the text in the SVG is sans-serif.

Edit: I just noticed that the special chars seem to be messed up in the word "Kreuzworträtsel".

What can I do to fix the issues?

$image = new Imagick();

$image->setResolution(288, 288);
$image->readImageBlob($svg);

$image->setImageformat('png24');

header('Content-Type: image/png');
echo $image->getImageBlob();

This is the SVG: https://www.dropbox.com/s/22hewf59cmcv92k/SVG.svg?dl=0

This is the converted PNG: https://www.dropbox.com/s/c5mihvmmlyu9kx8/PNG.png?dl=0
The quality problem is hard to see in the scaled down version, check out the link above.

Imagick::getVersion() returns ImageMagick 6.8.9-7 Q16 x86_64 2015-04-09 http://www.imagemagick.org.

Lars Ebert
  • 3,487
  • 2
  • 24
  • 46
  • 1
    It actually works fine for me, but I use the `rsvg` delegate. Try setting the desnity to 288 after creating the image but before reading in the SVG... `$image->setResolution(288,288);` – Mark Setchell Jul 21 '15 at 08:33
  • 1
    For what it's worth, I don't think it's a problem with the SVG. The Dropbox preview shows some random font (Georgia), but after saving locally and opening again in Firefox it shows correctly. It also displays pretty nigh on perfect in Illustrator. – Jongware Jul 21 '15 at 08:35
  • @MarkSetchell Thanks, I tried that (see the edited code snippet). The result stays the same. May I ask why that specific number of 288? – Lars Ebert Jul 21 '15 at 08:37
  • 2
    The default is 72dpi, and 288 is a nice simple way of getting 4x better resolution - 300 is probably as good. Old habit really! – Mark Setchell Jul 21 '15 at 08:39
  • Probable dupe of http://stackoverflow.com/questions/23085550/php-imagick-pdf-conversion-text-aliasing/23144243#23144243 – Danack Jul 21 '15 at 12:41

2 Answers2

0

You are almost certainly using a converter that has a bug in it.

Using your code and your source image I convert the image just fine using Ghostscript version 8.70 as the 'decode delegate' that ImageMagick will be using to actually do the conversion.

You should try upgrading whatever delegate is actually being used. If you are using Ghostscript, I recommend to upgrade to a 9.x version if possible, as that has lots of other bug fixes as well.

Danack
  • 24,939
  • 16
  • 90
  • 122
  • I actually am converting to PNG, not PDF. In addition, running `gs --version` tells me that I am using version 9.05. – Lars Ebert Jul 21 '15 at 12:56
  • It might have been a bug that existed in both the 8 and 9 branches. Anyway....whichever font it is using, the rendering is just botched, so it's almost certainly a bug in the converter rather than Imagick or ImageMagick. – Danack Jul 22 '15 at 11:42
0

The SVG refers exclusively, I think, to the Verdana font. Check if your ImageMagick system is aware of that font using:

identify -list font | more

or

identify -list font | grep -i verdana

If ImageMagick doesn't know that font, see my other post here.

Community
  • 1
  • 1
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432