ImageMagick(RSVG)不会在SVG中导入图像 [英] ImageMagick (RSVG) won't import images in SVG
问题描述
我正在尝试使用ImageMagick将SVG文件转换为PNG。
I'me trying to use ImageMagick to convert SVG files to PNG.
SVG文件如下:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
<image xlink:href="picture.jpg" width="200" height="200"/>
</svg>
无论我使用什么方法,最终结果都不包括图像。其他SVG元素已正确呈现。
No matter what method I use the final result doesn't include the image. Other SVG elements have rendered correctly.
我尝试过:
convert test.svg test.png
rsvg-convert -o test.png test.svg
我尝试更改图像路径以使用file:///,绝对路径,远程网址和每个网址编码的变体。我也使用和没有doctype格式化我的文件。
I've tried changing the image path to use file:///, absolute paths, remote urls, and url encoded variations of each. I've also formatted my file with and without a doctype.
我使用的是librsvg 2.36.3和ImageMagick 6.8.0-10
我去过能够使用phantomjs转换它们但是对于这一项任务似乎有点过分。
I'm using librsvg 2.36.3 and ImageMagick 6.8.0-10 I have been able to use phantomjs to convert them but it seems like overkill for this one task.
请帮助!
推荐答案
对我来说,安装gtk3(或者更具体地说是shared-mime-info帮助。(然后重新安装rsvg并使用绝对file:///uri for href AND将图像文件放在与svg文件相同的目录中)
更多信息(我仍然感到困惑):
More info (I'm still confused what exactly is going on):
-
我认为问题不是直接用rsvg,而是用gdk-pixbuf(2)库
I think the problem is not with rsvg directly, but with gdk-pixbuf(2) library
我在代码中找到了gdk-pixbuf用于加载图像的地方。我确认(使用printf debuggin)它不会抛出错误(似乎加载了pixbuf就好了)即使href中的uri没有指向文件。
I found the place in the code where gdk-pixbuf is used to load the image. I confirmed (using printf debuggin) that it doesn't throw an error (seems to load pixbuf just fine) even if the uri in the href does not point to a file.
gtk3依赖只应该是rsvg-view-3工具所必需的,而不是rsvg,但它似乎是(或者当我安装gtk3时被拉入的依赖之一)
the gtk3 dependency should only be necessary for rsvg-view-3 tool, not for rsvg, but it seems to be (or one of the dependencies that got pulled in when I installed gtk3)
即使在卸载gtk3后它仍然有效。它甚至在卸载gtk3之后仍然可以工作,然后重建rsvg(./configure检测到:gtk3:no),所以我认为它必须与我安装gtk3时拉出的依赖项之一有关:
It still works even after uninstalling gtk3. It even still works after uninstalling gtk3, then rebuilding rsvg (./configure detects: "gtk3: no"), so I figure it must have to do with one of the dependencies that got pulled when I installed gtk3:
atk-2.10.0-1-i686
atk-2.10.0-1-i686
(我是把这些留在这里,以防它不是我最后确定的lib)
(I'm leaving these here in case it's not the lib I identified in the end)
所以我尝试在组中删除这些deps并在其间重建和测试。结果证明它有效...
So I tried removing these deps in groups and rebuilding and testing in between. Turns out the one making it work is...
* shared-mime-info
这篇关于ImageMagick(RSVG)不会在SVG中导入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!