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.

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

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试