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

zol*_*iqa 10 macos homebrew svg imagemagick librsvg

我知道这个问题有几个在这里回答版本(这样的:ImageMagick的SVG转换为PNG不是RSVG工作启用),但实际上我无法找到一个真正解决我确切的问题.我的问题是:我有一个特定的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 )
Run Code Online (Sandbox Code Playgroud)

我安装了HomeBrew.如下所述:ImageMagick将SVG转换为PNG无法启用RSVG我使用此代码安装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)
Run Code Online (Sandbox Code Playgroud)

虽然这个:convert -list delegate | grep svg结果如下:

    svg =>          "rsvg-convert" -o "%o" "%i"
Run Code Online (Sandbox Code Playgroud)

我安装和卸载并重新安装了几次和方法,但没有改变,脚本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)
Run Code Online (Sandbox Code Playgroud)
  • ImageMagick 6.6.9-1
  • Mac OS X 10.9.4

小智 16

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

  1. 运行brew doctorbrew update
  2. 简单地使用brew reinstall imagemagick --with-librsvg// - 你可能拼错了!
  3. 试试吧.它应该工作!

它有用吗?

  • 这个答案似乎已经过时-当前的自制软件给出了错误`Error:invalid option:--with-librsvg` (2认同)

Jos*_*ban 7

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

用于brew info imagemagick在安装时查看可用选项.

--with-librsvg
    Build with librsvg support
Run Code Online (Sandbox Code Playgroud)

  • 不再支持自制选项 --with-librsvg。我收到错误 (2认同)

小智 5

If you want to use Homebrew to install imagemagick with svg support, you need to use an older version. They removed options from the installation process early 2019.

    brew install https://github.com/Homebrew/homebrew-core/raw/46a2ef7c9f0380b8e19f8dfe37270caa27581353/Formula/imagemagick.rb --with-librsvg
Run Code Online (Sandbox Code Playgroud)