使用librsvg / rsvg通过ImageMagick转换SVG图像

时间:2014-07-01 14:49:20

标签: macos svg imagemagick homebrew librsvg

我知道这个问题在这里有几个答案版本(像这样:ImageMagick convert SVG to PNG not working with RSVG enabled),但实际上我找不到真正解决我的确切问题的方法。我的问题是:我有一个特定的SVG文件(我将生成更多),SVG> PNG转换器进程内的ImageMagick无法完美转换。所以我需要将其更改为 librsvg ,因为它确实如此,我测试了这两行不同的结果:

    convert test.svg test.png  // ( img: http://tinyurl.com/px2lw3v )
    rsvg-convert test.svg -o test.png // ( img: http://tinyurl.com/lreu6sk )

我安装了HomeBrew。如下所述:ImageMagick convert SVG to PNG not working with RSVG enabled我使用此代码安装ImageMagick brew install imagemagick --use-rsvg。我意识到它没有安装 librsvg 所以我需要卸载它并重新安装如下:brew reinstall imagemagick --with-libsrvg librsvg --use-rsvg:这个已安装的imagemagick& librsvg一起到我的mac。但是没有关联它们:convert -list format | grep SVG结果为:

 MSVG  SVG       rw+   ImageMagick's own SVG internal renderer
  SVG  SVG       rw+   Scalable Vector Graphics (XML 2.9.0)
 SVGZ  SVG       rw+   Compressed Scalable Vector Graphics (XML 2.9.0)

虽然:convert -list delegate | grep svg导致:

    svg =>          "rsvg-convert" -o "%o" "%i"

我安装了&卸载&重新安装了几次&方式,但没有改变,脚本convert test.svg test.png没有librsvg这样做。我在/usr/local/Cellar/imagemagick/6.8.9-1/lib/ImageMagick/config-Q16/configure.xml中添加了带标签的行,但没有任何进展。我不知道该做什么以及如何连接ImageMagick并强制使用convert test.svg test.png的不同库。

感谢您的帮助。

更多信息:

    $ which convert
    /usr/local/bin/convert

    $ convert -version
    Version: ImageMagick 6.8.9-1 Q16 x86_64 2014-05-12 http://www.imagemagick.org
    Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
    Features: DPC Modules
    Delegates: bzlib freetype jng jpeg ltdl lzma png xml zlib

    $ otool -L $(which convert)
    /usr/local/bin/convert:
        /usr/local/Cellar/imagemagick/6.8.9-1/lib/libMagickCore-6.Q16.2.dylib (compatibility version 3.0.0, current version 3.0.0)
        /usr/local/Cellar/imagemagick/6.8.9-1/lib/libMagickWand-6.Q16.2.dylib (compatibility version 3.0.0, current version 3.0.0)
        /usr/local/lib/libfreetype.6.dylib (compatibility version 18.0.0, current version 18.2.0)
        /usr/lib/liblzma.5.dylib (compatibility version 6.0.0, current version 6.3.0)
        /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
        /usr/local/lib/libltdl.7.dylib (compatibility version 11.0.0, current version 11.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

    $ which rsvg-convert
    /usr/local/bin/rsvg-convert

    $ otool -L $(which rsvg-convert)
    /usr/local/bin/rsvg-convert:
        /usr/local/Cellar/librsvg/2.36.3/lib/librsvg-2.2.dylib (compatibility version 39.0.0, current version 39.3.0)
        /usr/local/lib/libgdk_pixbuf-2.0.0.dylib (compatibility version 3001.0.0, current version 3001.8.0)
        /usr/local/lib/libgio-2.0.0.dylib (compatibility version 4001.0.0, current version 4001.0.0)
        /usr/local/lib/libpangocairo-1.0.0.dylib (compatibility version 3601.0.0, current version 3601.5.0)
        /usr/local/lib/libpango-1.0.0.dylib (compatibility version 3601.0.0, current version 3601.5.0)
        /usr/local/lib/libgobject-2.0.0.dylib (compatibility version 4001.0.0, current version 4001.0.0)
        /usr/local/lib/libcairo.2.dylib (compatibility version 11203.0.0, current version 11203.16.0)
        /usr/local/lib/libpng16.16.dylib (compatibility version 29.0.0, current version 29.0.0)
        /usr/local/lib/libcroco-0.6.3.dylib (compatibility version 4.0.0, current version 4.1.0)
        /usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.9.0)
        /usr/local/lib/libgthread-2.0.0.dylib (compatibility version 4001.0.0, current version 4001.0.0)
        /usr/local/lib/libglib-2.0.0.dylib (compatibility version 4001.0.0, current version 4001.0.0)
        /usr/local/opt/gettext/lib/libintl.8.dylib (compatibility version 10.0.0, current version 10.2.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
  • ImageMagick 6.6.9-1
  • Mac OS X 10.9.4

3 个答案:

答案 0 :(得分:16)

我试过,我的解决方案在Mac上:

  1. 运行brew doctorbrew update
  2. 简单地使用brew reinstall imagemagick --with-librsvg // - 您可能拼错了!
  3. 试一试。它应该工作!
  4. 有用吗?

答案 1 :(得分:7)

(只需在Zoltan的回答中添加更多上下文)

使用brew info imagemagick查看安装时的可用选项。

--with-librsvg
    Build with librsvg support

答案 2 :(得分:4)

如果要使用Homebrew安装具有svg支持的imagemagick,则需要使用旧版本。他们从2019年初的安装过程中删除了选项。

    brew install https://github.com/Homebrew/homebrew-core/raw/46a2ef7c9f0380b8e19f8dfe37270caa27581353/Formula/imagemagick.rb --with-librsvg