linux:svg转png(rsvg-convert 2.50.7/ubuntu 21.10)
一,直接用ImageMagick把svg转为png时有瑕疵
1,例子:原图:
转换命令:
liuhongdi@lhdpc:/data/work/tmpimg$ convert go-logo-blue.svg go.png
效果如下:
转换完后图片不完整
2,查看convert是否调用rsvg-convert
确实调用了,但不确定为什么会出现此情况
liuhongdi@lhdpc:/data/work/tmpimg$ convert -list delegate | grep 'svg ='
svg => "rsvg-convert' -o '%o' '%i"
二,直接使用rsvg-convert命令:
liuhongdi@lhdpc:/data/work/tmpimg$ rsvg-convert -w 1200 go-logo-blue.svg -o go1200.png
效果:
说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/07/08/linux-svg-zhuan-png-rsvgconvert-2-50-7-ubuntu-21-10/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
三,查看rsvg-convert的版本/帮助/所属安装包
版本:
liuhongdi@lhdpc:/data/work/tmpimg$ rsvg-convert -v
rsvg-convert version 2.50.7
帮助:
liuhongdi@lhdpc:/data/work/tmpimg$ rsvg-convert --help
Usage:
rsvg-convert [OPTION…] [FILE...] - SVG Converter
Help Options:
-?, --help Show help options
Application Options:
-d, --dpi-x=<float> pixels per inch [optional; defaults to 90dpi]
-p, --dpi-y=<float> pixels per inch [optional; defaults to 90dpi]
-x, --x-zoom=<float> x zoom factor [optional; defaults to 1.0]
-y, --y-zoom=<float> y zoom factor [optional; defaults to 1.0]
-z, --zoom=<float> zoom factor [optional; defaults to 1.0]
-w, --width=<int> width [optional; defaults to the SVG's width]
-h, --height=<int> height [optional; defaults to the SVG's height]
-f, --format=[png, pdf, ps, eps, svg, xml, recording] save format [optional; defaults to 'png']
-o, --output output filename [optional; defaults to stdout]
-i, --export-id=<object id> SVG id of object to export [optional; defaults to exporting all objects]
-a, --keep-aspect-ratio whether to preserve the aspect ratio [optional; defaults to FALSE]
-b, --background-color=[black, white, #abccee, #aaa...] set the background color [optional; defaults to None]
-s, --stylesheet Filename of CSS stylesheet
-u, --unlimited Allow huge SVG files
--keep-image-data Keep image data
--no-keep-image-data Don't keep image data
-v, --version show version information
所属的包:
liuhongdi@lhdpc:/data/work/tmpimg$ dpkg-query -S /usr/bin/rsvg-convert
librsvg2-bin: /usr/bin/rsvg-convert
可以看到所属的包是 librsvg2-bin