Convertation SVG to PNG with transparency
Posted: 2013-01-19T14:31:36-07:00
Below source code that converts SVG image to png
//Wrong result
$mw = NewMagickWand();
$transparentColor = NewPixelWand();
PixelSetColor($transparentColor, 'transparent');
MagickReadImage($mw, 'from.svg');
MagickSetImageBackgroundColor($mw, $transparentColor);
MagickSetImageFormat($mw, 'png32');
MagickWriteImage($mw, 'to.png'); //Image with white color instead of transparent
//Works OK
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readimage('from.svg');
$im->setImageFormat("png32");
$im->writeimage('to.png'); //Image with transparent background
I think the error in ImageMagick extension. Do you have any ideas how to convert SVG to PNG with transparency using MagickWand?
//Wrong result
$mw = NewMagickWand();
$transparentColor = NewPixelWand();
PixelSetColor($transparentColor, 'transparent');
MagickReadImage($mw, 'from.svg');
MagickSetImageBackgroundColor($mw, $transparentColor);
MagickSetImageFormat($mw, 'png32');
MagickWriteImage($mw, 'to.png'); //Image with white color instead of transparent
//Works OK
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readimage('from.svg');
$im->setImageFormat("png32");
$im->writeimage('to.png'); //Image with transparent background
I think the error in ImageMagick extension. Do you have any ideas how to convert SVG to PNG with transparency using MagickWand?