doumaque6551 2015-02-04 22:02
浏览 269
已采纳

ImageMagick SVG到PNG转换会删除渐变

I'm trying to allow users to upload an SVG image through a CMS and generate a fallback PNG so that when the CMS displays the content on the front end the PNG fallback is shown for older browsers.

The problem is that when I upload an SVG the PNG output is a bit off, gradients seem to be missing as shown in the screenshot below.

SVG on the left PNG on the right

In these tests I'm just using ImageMagick commandline as below but have tried it through the CMS upload using Imagick with the same result.

convert gallardo.svg gallardo.png

Imagick version sets background to transparent as suggested in other threads but PNG output is the same as commandline.

class ResampleSvgUpload extends DataExtension {

    function onAfterUpload() {
        if($this->isSvg()){
            $this->resample();
        }
    }

    function onAfterWrite() {
        if($this->isSvg()){
            $this->resample();
        }
    }

    function isSvg() {
        $extension = strtolower($this->owner->getExtension());
        return ($extension == 'svg') ? true : false;
    }

    function resample() {
        $original = $this->owner->getFullPath();
        $resampled = $original . '.png';    
        $imagick = new Imagick($original);
        $imagick->setBackgroundColor(new ImagickPixel('transparent'));
        $imagick->setImageFormat('png');
        $imagick->writeImage($resampled);
    }
}

I'm using:

  • ImageMagick 6.9.0-3
  • Imagick 3.1.0RC2
  • PHP 5.3.29
  • OSX Yosemite 10.10
  • 写回答

1条回答 默认 最新

  • duan0427 2015-02-05 12:22
    关注

    ImageMagick does not do the conversion of SVG itself, instead it delegates that task to a 3rd party program. You can find which program is being used by adding the -verbose option to the convert command.

    The issue will almost certainly be being caused by a bug in that underlying program - and will hopefully go away when you upgrade to a newer version of it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站