views:

28

answers:

1

First image was properly exported by Inscape, second by following code. I need same output from inkscape and imagick.

corect image

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>
A: 

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...

Josh
PHP version => 5.3.2-1ubuntu4.2imagick module version => 2.1.1-rc1
Jan Tojnar
@Jan: Thanks. I posted a few more suggestions. Is this the stock PHP/imagick that's installed via Ubuntu's `apt-get`? What version of Ububtu? I can set up a virtual machine and try this for you on my end. I'm often in [the PHP chat room](http://chat.meta.stackoverflow.com/rooms/60/php) if you want to talk this through.
Josh
i use ubuntu 10.04 lucid lynx, imagick and php were installed by synaptic (apt frontend). I also tested it on hosting with PHP Version 5.3.3 and imagick module version 2.3.0
Jan Tojnar
@Jan: Sorry, it was a crazy day and I wasn't able to test this for you. I'll try this weekend. Maybe somebody else will chime in with a more definite solution.
Josh