- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 PHP 的 Imagick 类将 SVG 转换为 PNG。
转换成功但似乎忽略了任何填充模式。这是我的代码:
<?php
$svg = <<<SVG
<?xml version="1.0"?>
<svg>
<defs>
<pattern id="myPattern" x="0" y="0" width="20" height="20" patternUnits="userSpaceOnUse">
<rect width="20" height="20" fill="#ffffff" />
<circle cx="10" cy="10" r="5" stroke="#0000bb" fill="#dd8d8d" />
</pattern>
</defs>
<text y="100%"
stroke="#ff0000"
fill="url('#myPattern')"
font-size="40pt">
Hello <tspan style="font-style: italic">SVG</tspan> world!
</text>
</svg>
SVG;
try{
$image = new Imagick();
$image->setBackgroundColor(new ImagickPixel('transparent'));
$image->readImageBlob( $svg );
$image->setImageFormat('png32');
$image->setImageCompressionQuality(100);
file_put_contents('text-fill-example.png', $image);
}
catch(ImagickException $e){
error_log($e);
}
在上面的例子中,字母应该包含点状图案。如果您在 Inkscape 中将上述 svg 代码作为文件打开,则图案会正确显示。此外,如果您将 svg 代码嵌入到 html 中,它会在现代浏览器中正确显示该模式。
如果我尝试从命令行转换,模式也会被忽略:
$ convert -verbose text-fill-example.svg text-fill-example.png
text-fill-example.svg SVG 358x36 358x36+0+0 16-bit DirectClass 433B 0.020u 0:00.030
text-fill-example.svg=>text-fill-example.png SVG 358x36 358x36+0+0 16-bit PseudoClass 256c 8.19KB 0.010u 0:00.009
$ convert --version
Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
有人知道吗?
最佳答案
原来我的 SVG 代码并不完全有效。我用了W3C validator最终得到一些 100% 有效且现在有效的标记:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<defs>
<pattern id="myPattern" x="0" y="0" width="20" height="20" patternUnits="userSpaceOnUse">
<rect width="20" height="20" fill="#ffffff" />
<circle cx="10" cy="10" r="5" stroke="#0000bb" fill="#dd8d8d" />
</pattern>
</defs>
<text y="100%"
stroke="#ff0000"
fill="url(#myPattern)"
font-size="40pt">
Hello <tspan style="font-style: italic">SVG</tspan> world!
</text>
</svg>
关于php - 使用 ImageMagic 将 SVG 转换为 PNG 会忽略填充图案 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35723456/
尝试使用imagemagick 需要同步使用imagemagick。 即下一个代码应该只在图像转换完成后执行(无论错误还是成功) 我只看到一个解决方案 deasync : const ImageMag
我正在尝试根据文件名和大小调整图像大小: import subprocess import os os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hi
我的任务是“将图像读入像素图,然后将其转换为纹理贴图”。因此,仅对于像素图部分,请听我说完并告诉我我的想法是否正确以及是否有更简单的方法。我正在使用的图书馆文档:http://www.imagemag
我正在编写一个脚本,用透明色去除背景色。 脚本是这样进行的,并给出了正确的结果,可以区分紫红色。 $val = 65535/40; //divide by fuzz d
我正在寻找一种解决方案来生成网站列表屏幕截图的缩略图,并将其保存到磁盘。 我发现以下命令可以做到这一点。我在 ubuntu 中得到了一个有效的 shell 脚本,它可以很好地生成图像。 (CutyCa
您好,我想转换一些带有圆角的图像。我在他们的网站上找到了如何使用 ImageMagic 完成此操作 convert thumbnail.gif \ \( +clone -crop 16x1
我从这里 https://github.com/Zulko/moviepy 使用 python 的 moviepy 模块 我已经成功安装了moviepy和必要的模块。但是,当我尝试运行在视频中添加文本
我试图使用 ImageMagick 库以在 php 中以编程方式对图像进行 chorma 键。到目前为止,我已经在我的服务器上安装了 ImageMagick 扩展,并确保它在终端本身中使用一些简单的命
我尝试编译 http://www.imagemagick.org/script/magick-wand.php 中的 ImageMagic c 代码在安尤塔。我成功下载并编译了ImageMagic然后
我正在用 C 编程。我想使用 ImageMagick 库,但有些功能无法解决。 这是我的 cMakeList.txt 文件: cmake_minimum_required(VERSION 3.3) p
我正在使用 PHP 的 Imagick 类将 SVG 转换为 PNG。 转换成功但似乎忽略了任何填充模式。这是我的代码:
我使用 FabricJs 在 Canvas 上创建了一个带有一些图片和文本的设计 (270x470),然后我通过 fabricJS 的 canvas.toJSON() 方法以 JSON 格式导出所有图
我是一名优秀的程序员,十分优秀!