Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imagick doesn't render svg opacity properly

I need same output from Inkscape and Imagick.

This is the expected result, exported from Inkscape.

corect image

However, the PHP code below outputs the following faulty result.

wrong image

PHP code:

<?php
$im = new Imagick();

$im->setResolution(400,400);
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readImageBlob(str_replace(array("color1", "color2"), array("yellow", "blue"), file_get_contents("img.svg")));

$im->setImageFormat("png");
header("Content-type: image/png");
echo $im;
?>

SVG code:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="400" height="400">
<rect width="100%" height="100%" fill="green" />
<path d="M250 150 L150 350 L350 350 Z" opacity="0.9" fill="color1" />
<path d="M150 50 L50 250 L250 250 Z" opacity="0.9" fill="color2" />
</svg>
like image 502
Jan Tojnar Avatar asked Sep 02 '10 20:09

Jan Tojnar


1 Answers

What version of PHP and ImageMagick are you running? Please share the relevant output of phpinfo(). Could this ImageMagick bug be affecting you? Or if you're not up to date, could another ImageMagic bug be affecting you?

EDIT: I don't have easy access to a server with PHP's ImageMagick libraries installed at the moment, but if I find one, I'll test the code provided and post my results.

EDIT2: Looks like others have the same issue, unless that forum post was also yours...

According to this forum post, you could try:

$im->setImageFormat("png32");

One person reported that worked, but another said it did not...

like image 50
Josh Avatar answered Oct 19 '22 03:10

Josh