2010-09-02 20:36


  • svg
  • imagick
  • php
  • opacity

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:

$im = new Imagick();

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

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

SVG code:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="" 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" />
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongzha3058 dongzha3058 6年前

    This is already fixed in current version of Imagick.

    点赞 评论 复制链接分享
  • duancunsu9209 duancunsu9209 11年前

    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:


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

    点赞 评论 复制链接分享
  • doutizong8099 doutizong8099 9年前

    Inkscape uses the not ubiquitously supported opacity property. Use fill-opacity and stroke-opacity instead.

    点赞 评论 复制链接分享