Answers:
convert -resize 128x128 input.svg output.png
如果输入的画布大小小于给定的大小,则将在不重新采样的情况下放大输出。要获得更高质量的结果,请添加-density
参数:
convert -density 500 -resize 128x128 input.svg output.png
ImageMagick栅格将图像矢量转换为其画布分辨率,默认密度为72 dpi。
为了通过适当的采样进行放大,您可以指定一个较高的值,例如上述样本中的500 dpi。
对于大尺寸画布,使用过高的栅格密度可能是性能问题。最低和理想的栅格密度是: raster_density = raster_size / original_size * original_density
理想的光栅密度将直接将图像输出到期望的尺寸(-resize
不需要)。但是,由于可能会出现浮点数近似值,因此建议为像素完美的结果使用稍高的值和调整大小。
您可以使用ImageMagick的转义百分比来获得原始大小和密度:
convert input.svg -format "%w %h %[resolution.x] %[resolution.y]" info:
请注意,ImageMagick不能处理SVG的完整规范。如果无法正确渲染形状,请查看有关选择ImageMagick SVG渲染器的线程。
rsvg
从下面的答案中自己找到的,但实际上是我开始使用ImageMagick的时候了。
convert: unable to read font
(null)'@ error / annotate.c / RenderFreetype / 1153.`错误,我通过解决了这个错误brew install gs
,但是即使convert干净地运行,结果图像也是垃圾。
-background transparent
,否则convert使用白色背景。
inkscape in.svg --export-png=out.png
(例如,从superuser.com/a/493028/316154)
双方rsvg
并inkscape
可以:
$ rsvg
Usage: rsvg [OPTIONS...] file.svg file.png
-d, --dpi-x=<float> pixels per inch
-p, --dpi-y=<float> pixels per inch
-x, --x-zoom=<float> x zoom factor
-y, --y-zoom=<float> y zoom factor
-w, --width=<int> width
-h, --height=<int> height
-q, --quality=<int> JPEG quality
-f, --format=[png, jpeg] save format
-v, --version show version information
Help options:
-?, --help Show this help message
--usage Display brief usage message
和:
$ inkscape --help
Usage: inkscape [OPTIONS...] [FILE...]
Available options:
-V, --version Print the Inkscape version number
-z, --without-gui Do not use X server (only process
files from console)
-g, --with-gui Try to use X server (even if
$DISPLAY is not set)
-f, --file=FILENAME Open specified document(s) (option
string may be excluded)
-p, --print=FILENAME Print document(s) to specified
output file (use '| program' for
pipe)
-e, --export-png=FILENAME Export document to a PNG file
-d, --export-dpi=DPI The resolution used for exporting
SVG into bitmap (default 90)
-a, --export-area=x0:y0:x1:y1 Exported area in SVG user units
(default is the canvas; 0,0 is
lower-left corner)
-D, --export-area-drawing Exported area is the entire
drawing (not canvas)
-C, --export-area-canvas Exported area is the entire canvas
--export-area-snap Snap the bitmap export area
outwards to the nearest integer
values (in SVG user units)
-w, --export-width=WIDTH The width of exported bitmap in
pixels (overrides export-dpi)
-h, --export-height=HEIGHT The height of exported bitmap in
pixels (overrides export-dpi)
-i, --export-id=ID The ID of the object to export
-j, --export-id-only Export just the object with
export-id, hide all others (only
with export-id)
-t, --export-use-hints Use stored filename and DPI hints
when exporting (only with
export-id)
-b, --export-background=COLOR Background color of exported
bitmap (any SVG-supported color
string)
-y, --export-background-opacity=VALUE Background opacity of exported
bitmap (either 0.0 to 1.0, or 1 to
255)
-l, --export-plain-svg=FILENAME Export document to plain SVG file
(no sodipodi or inkscape
namespaces)
-P, --export-ps=FILENAME Export document to a PS file
-E, --export-eps=FILENAME Export document to an EPS file
-A, --export-pdf=FILENAME Export document to a PDF file
-T, --export-text-to-path Convert text object to paths on
export (EPS)
-F, --export-embed-fonts Embed fonts on export (Type 1
only) (EPS)
-B, --export-bbox-page Export files with the bounding box
set to the page size (EPS)
-X, --query-x Query the X coordinate of the
drawing or, if specified, of the
object with --query-id
-Y, --query-y Query the Y coordinate of the
drawing or, if specified, of the
object with --query-id
-W, --query-width Query the width of the drawing or,
if specified, of the object with
--query-id
-H, --query-height Query the height of the drawing
or, if specified, of the object
with --query-id
-S, --query-all List id,x,y,w,h for all objects
-I, --query-id=ID The ID of the object whose
dimensions are queried
-x, --extension-directory Print out the extension directory
and exit
--vacuum-defs Remove unused definitions from the
defs section(s) of the document
--verb-list List the IDs of all the verbs in
Inkscape
--verb=VERB-ID Verb to call when Inkscape opens.
--select=OBJECT-ID Object ID to select when Inkscape
opens.
Help options:
-?, --help Show this help message
--usage Display brief usage message