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.

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

报告相同问题?

悬赏问题

  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。
  • ¥15 GitHubssh虚拟机连接不上
  • ¥15 装完kali之后下载Google输入法 重启电脑后出现以下状况 且退不出去 桌面消失 反复重启没用
  • ¥15 ESP-IDP-BLE配网连接wifi