[SVG到php中的PNG图像转换

问题描述 投票:1回答:1

我想将SVG图像转换为具有透明背景的PNG文件。我正在使用下面的代码在php中使用imagick对其进行转换,但它会产生黑色背景的图像。

        $image = new imagick();
        //set transparent background
        $image->setBackgroundColor(new ImagickPixel('transparent'));
        $image->setFormat('svg');
        $image->readImageBlob(file_get_contents("image.svg"));
        $image->setImageFormat("png32");
        $image->resizeImage(265,195, Imagick::FILTER_LANCZOS, 1);
        $image->writeImage('result.png');

[谁能帮我如何使用PHP将上述svg图像转换为png图像。任何帮助,将不胜感激。

php imagick image-conversion
1个回答
0
投票

不为我工作,我尝试使用上面的代码,添加[]后会生成白色图像

$image->setBackgroundColor(new ImagickPixel('transparent')); 

它创建黑色图像,

在我的SVG中,我有自定义的文本和图像I have added sample here

© www.soinside.com 2019 - 2024. All rights reserved.