1RSVG-CONVERT() RSVG-CONVERT()
2
3
4
6 rsvg-convert - Render SVG documents to PNG images, or convert them to
7 PDF or PS.
8
10 Convert an SVG to PNG at its "natural size" and write it to standard
11 output:
12 rsvg-convert input.svg > output.png
13
14 Specify an output filename; the input filename must be the last argu‐
15 ment:
16 rsvg-convert --output=output.png input.svg
17
18 Configure dots-per-inch (DPI) for SVGs that have physical units, as in
19 <svg width="5cm" height="3cm"> - the default is 96 DPI:
20 rsvg-convert --dpi-x=300 --dpi-y=300 input.svg > output.png
21
22 Render an SVG at a specific pixel size, scaled proportionally:
23 rsvg-convert --width=1024 --height=768 --keep-aspect-ratio input.svg
24 > output.png
25
27 rsvg-convert renders SVG documents into PNG raster images, or converts
28 them to PDF or PS as vector objects. By default rsvg-convert will ren‐
29 der an SVG document to a raster PNG image and write it to standard out‐
30 put:
31 rsvg-convert input.svg > output.png
32
33 To select another format, use the --format option:
34 rsvg-convert --format=pdf input.svg > output.pdf
35
36 You can use rsvg-convert as part of a pipeline; without an argument for
37 the input filename it will read the document from standard input:
38 cat input.svg | rsvg-convert > output.png
39
40 SPECIFYING THE RENDERED SIZE
41 You can use the --width and --height options to specify the size of the
42 output image. Most of the time you should specify --keep-aspect-ratio
43 to scale the image proportionally; for compatibility with old versions
44 this is not the default.
45 rsvg-convert --width=100 --height=200 --keep-aspect-ratio input.svg
46 > output.png
47
48 You can also specify dimensions as CSS lengths, for example 10px or
49 8.5in. The unit specifiers supported are as follows:
50
51 ┌───┬────────────────────────────┐
52 │px │ pixels (the unit specifier │
53 │ │ can be omitted) │
54 ├───┼────────────────────────────┤
55 │in │ inches │
56 ├───┼────────────────────────────┤
57 │cm │ centimeters │
58 ├───┼────────────────────────────┤
59 │mm │ millimeters │
60 ├───┼────────────────────────────┤
61 │pt │ points, 1/72 inch │
62 ├───┼────────────────────────────┤
63 │pc │ picas, 1/6 inch │
64 └───┴────────────────────────────┘
65
66 The following will create a 600*900 pixel PNG, or 2*3 inches at 300
67 dots-per-inch:
68 rsvg-convert --width=2in --height=3in --keep-aspect-ratio
69 --dpi-x=300 --dpi-y=300 input.svg > output.png
70
71 This will scale an SVG document to fit in an A4 page and convert it to
72 PDF:
73 rsvg-convert --format=pdf --width=210mm --height=297mm --keep-as‐
74 pect-ratio input.svg > output.pdf
75
76 SPECIFYING A PAGE SIZE
77 By default the size of the output comes from the rendered size, which
78 can be specified with the --width and --height options, but you can
79 specify a page size independently of the rendered size with
80 --page-width and --page-height, together with --top and --left to con‐
81 trol the position of the rendered image within the page. In short:
82
83 • --page-width and --page-height together - set the page size.
84
85 • --top and --left - set the margins.
86
87 • --width and --height - set the rendered size.
88
89 This will create a PDF with a landscape A4 page, by scaling an SVG doc‐
90 ument to 10*10 cm, and placing it with its top-left corner 5 cm away
91 from the top and 8 cm from the left of the page:
92 rsvg-convert --format=pdf --page-width=297mm --page-height=210mm
93 --width=10cm --height=10cm --keep-aspect-ratio --top=5cm --left=8cm
94 input.svg > output.pdf
95
96 SPECIFYING A SCALE FACTOR INSTEAD OF A RENDERED SIZE
97 The --zoom option lets you scale the natural size of an SVG document.
98 For example, if input.svg is a document with a declared size of 100*200
99 pixels, then the following command will render it at 250*500 pixels
100 (zoom 2.5):
101 rsvg-convert --zoom=2.5 input.svg > output.png
102
103 You can limit the maximum scaled size by specifying the --width and
104 --height options together with --zoom. Here, the image will be scaled
105 10x, but limited to 1000*1000 pixels at the most:
106 rsvg-convert --zoom=10 --width=1000 --height=1000 input.svg > out‐
107 put.png
108
109 If you need different scale factors for the horizontal and vertical di‐
110 mensions, use the --x-zoom and --y-zoom options instead of --zoom.
111
112 CREATING A MULTI-PAGE DOCUMENT
113 The "pdf", "ps", and "eps" output formats support multiple pages. These
114 can be created by combining multiple input SVG files. For example, this
115 PDF file will have three pages:
116 rsvg-convert --format=pdf page1.svg page2.svg page3.svg > out.pdf
117
118 The size of each page will be computed, separately, as described in the
119 DEFAULT OUTPUT SIZE section. This may result in a PDF being produced
120 with differently-sized pages. If you need to produce a PDF with all
121 pages set to exactly the same size, use the --page-width and
122 --page-height options.
123
124 For example, the following command creates a three-page PDF out of
125 three SVG documents. All the pages are portrait US Letter, and each SVG
126 is scaled to fit so that there is a 1in margin around each page (hence
127 the width of 6.5in and height of 9in for the rendered size).
128 rsvg-convert --format=pdf --page-width=8.5in --page-height=11in
129 --width=6.5in --height=9in --keep-aspect-ratio --top=1in --left=1in
130 pg1.svg pg2.svg pg3.svg > out.pdf
131
132 CONVERSION OF PIXELS BASED ON THE DOTS-PER-INCH
133 rsvg-convert uses the --dpi-x and --dpi-y options to configure the
134 dots-per-inch (DPI) by which pixels will be converted to/from physical
135 units like inches or centimeters. The default for both options is 96
136 DPI.
137
138 Consider this example SVG, which is nominally declared to be 2*3 inches
139 in size:
140
141 <svg xmlns="http://www.w3.org/2000/svg" width="2in" height="3in">
142 <!-- graphical objects here -->
143 </svg>
144
145 The following commands create PNGs of different sizes for the example
146 SVG above:
147 rsvg-convert two-by-three.svg > output.png #### creates a 192*288
148 pixel PNG
149
150 rsvg-convert --dpi-x=300 --dpi-y=300 two-by-three.svg > output.png
151 #### creates a 600*900 pixel PNG
152
153 Note that the final pixel dimensions are rounded up to the nearest
154 pixel, to avoid clipping off the right/bottom edges. In the following
155 example, rsvg-convert will generate a PNG 300x300 pixels in size:
156 rsvg-convert --width=299.5 --height=299.4 input.svg > output.png
157 #### outputs 300x300 pixel PNG with a fractionally-scaled image
158
159 If you specify dimensions in physical units, they will be multiplied by
160 the dots-per-inch (DPI) value to obtain dimensions in pixels. For exam‐
161 ple, this will generate a 96x96 pixel PNG, since it is 1x1 inch at the
162 default 96 DPI:
163 rsvg-convert --width=1in --height=1in input.svg > output.png ####
164 outputs 96x96 pixel PNG
165
166 Correspondingly, this will generate a 300x300 pixel PNG, since it is
167 1x1 inch at 300 DPI:
168 rsvg-convert --width=1in --height=1in --dpi-x=300 --dpi-y=300 in‐
169 put.svg > output.png #### outputs 300x300 pixel PNG
170
171 DEFAULT OUTPUT SIZE
172 If you do not specify --width or --height options for the output size,
173 rsvg-convert will figure out a "natural size" for the SVG as follows:
174
175 • SVG with width and height in pixel units (px): <svg width="96px"
176 height="192px"> For PNG output, those same dimensions in pixels are
177 used. For PDF/PS/EPS, that pixel size is converted to physical units
178 based on the DPI value (see the --dpi-x and --dpi-y options),
179
180 • SVG with width and height in physical units: <svg width="1in"
181 height="2in"> For PNG output, the width and height attributes get
182 converted to pixels, based on the DPI value (see the --dpi-x and
183 --dpi-y options). For PDF/PS/EPS output, the width/height in physical
184 units define the size of the PDF unless you specify options for the
185 page size; see SPECIFYING A PAGE SIZE above.
186
187 • SVG with viewBox only: <svg viewBox="0 0 20 30"> The size of the
188 viewBox attribute gets used for the pixel size of the image as in the
189 first case above.
190
191 • SVG with width and height in percentages: <svg width="100%"
192 height="100%" viewBox="0 0 20 30"> Percentages are meaningless unless
193 you specify a viewport size with the --width and --height options. In
194 their absence, rsvg-convert will just use the size of the viewBox for
195 the pixel size, as described above.
196
197 • SVG with no width, height, or viewBox: rsvg-convert will measure the
198 extents of all graphical objects in the SVG document and render them
199 at 1:1 scale (1 pixel for each CSS px unit). It is strongly recom‐
200 mended that you give SVG documents an explicit size with the width,
201 height, or viewBox attributes.
202
203 BACKGROUND COLOR
204 You can use the --background-color option (-b for short) to specify the
205 background color that will appear in parts of the image that would oth‐
206 erwise be transparent. This option accepts the same syntax as the CSS
207 color property, so you can use #rrggbb syntax, or CSS named colors like
208 white, or rgba().
209 rsvg-convert --background-color=white input.svg > output.png ####
210 opaque white
211 rsvg-convert -b '#ff000080' input.svg > output.png #### translucent
212 red - use shell quotes so the # is not interpreted as a comment
213
214 SELECTING A LANGUAGE FOR MULTI-LANGUAGE SVG
215 An SVG document can use the <switch> element and children with the sys‐
216 temLanguage attribute to provide different content depending on the
217 user's language. For example:
218
219 <svg xmlns="http://www.w3.org/2000/svg" width="200" height="100">
220 <rect width="200" height="100" fill="white"/>
221 <g transform="translate(30, 30)" font-size="20">
222 <switch allowReorder="yes">
223 <text systemLanguage="es">Español</text>
224 <text systemLanguage="de">Deutsch</text>
225 <text systemLanguage="fr">Français</text>
226 <text>English fallback</text>
227 </switch>
228 </g>
229 </svg>
230
231 You can use the --accept-language option to select which language to
232 use when rendering. This option accepts strings formatted like an HTTP
233 Accept-Language header, which is a comma-separated list of BCP47 lan‐
234 guage tags: https://www.rfc-editor.org/info/bcp47
235 rsvg-convert --accept-language=es-MX input.svg > output.png #### se‐
236 lects Mexican Spanish; renders "Español".
237
238 USER STYLESHEET
239 You can include an extra CSS stylesheet to be used when rendering an
240 SVG document with the --stylesheet option. The stylesheet will have the
241 CSS user origin, while styles declared in the SVG document will have
242 the CSS author origin. This means your extra stylesheet's styles will
243 override or augment the ones in the document, unless the document has
244 !important in its styles.
245 rsvg-convert --stylesheet=extra-styles.css input.svg > output.png
246
247 For example, if this is input.svg:
248
249 <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
250 <rect width="200" height="100" fill="white"/>
251
252 <rect class="recolorable" x="10" y="10" width="50" height="50" fill="red"/>
253
254 <text x="10" y="80" font-size="20" fill="currentColor">Hello</text>
255 </svg>
256
257 And this is extra-styles.css:
258
259 .recolorable { fill: blue; }
260
261 * { color: green; }
262
263 Then the PNG created by the command above will have these elements:
264
265 • A blue square instead of a red one, because of the selector for the
266 the recolorable class.
267
268 • Text in green, since a fill with currentColor gets substituted to the
269 value of the color property, and the * selector applies to all ele‐
270 ments.
271
273 GENERAL OPTIONS
274 -f format, --format=[png, pdf, ps, eps, svg]
275 Output format for the rendered document. Default is png.
276
277 -o filename, --output filename
278 Specify the output filename. If unspecified, outputs to standard
279 output.
280
281 -v, ``--version
282 Display what version of rsvg-convert you are running.
283
284 --help Display a summary of usage and options.
285
286 SIZE AND POSITION
287 In the following, <length> values must be specified with CSS <length>
288 syntax: https://developer.mozilla.org/en-US/docs/Web/CSS/length. For
289 example, 640px or 25cm.
290
291 --page-width <length> --page-height <length>
292 Page size of the output document; both options must be used to‐
293 gether. The default is to use the image's width and height as
294 modified by the options below.
295
296 --top <length>
297 Distance between top edge of the page and the rendered image.
298 Default is 0.
299
300 --left <length>
301 Distance between left edge of the page and the rendered image.
302 Default is 0.
303
304 -w <length>, --width <length>
305 Width of the rendered image. If unspecified, the natural width
306 of the image is used as the default. See the section "SPECIFYING
307 DIMENSIONS" above for details.
308
309 -h <length>, --height <length>
310 Height of the rendered image. If unspecified, the natural height
311 of the image is used as the default. See the section "SPECIFYING
312 DIMENSIONS" above for details.
313
314 -a, --keep-aspect-ratio
315 Specify that the aspect ratio is to be preserved, i.e. the image
316 is scaled proportionally to fit in the --width and --height. If
317 not specified, aspect ratio will not be preserved.
318
319 -d number, --dpi-x number
320 Set the X resolution of the image in pixels per inch. Default is
321 96 DPI.
322
323 -p number, --dpi-y number
324 Set the Y resolution of the image in pixels per inch. Default is
325 96 DPI.
326
327 -x number, --x-zoom number
328 Horizontal scaling factor. Default is 1.0.
329
330 -y number, --y-zoom number
331 Vertical factor factor. Default is 1.0.
332
333 -z number, --zoom number
334 Horizontal and vertical scaling factor. Default is 1.0.
335
336 CONTROLLING THE RENDERED APPEARANCE
337 -b <color>, --background-color [black, white, #abccee, #aaa...]
338 Specify the background color. If unspecified, none is used as
339 the default; this will create transparent PNGs, or PDF/PS/EPS
340 without a special background. The <color> must be specified in
341 CSS <color> syntax:
342 https://developer.mozilla.org/en-US/docs/Web/CSS/color_value.
343 For example, black, #ff0000, rgba(0.0, 1.0, 0.0, 1.0).
344
345 -s filename.css, --stylesheet filename.css
346 Filename of a custom CSS stylesheet.
347
348 -l language-tag, --accept-language [es-MX,fr,en]
349 Specify which languages will be used for SVG documents with mul‐
350 tiple languages. The string is formatted like an HTTP Ac‐
351 cept-Language header, which is a comma-separated list of BCP47
352 language tags: https://www.rfc-editor.org/info/bcp47. The de‐
353 fault is to use the language specified by environment variables;
354 see the section "ENVIRONMENT VARIABLES" below.
355
356 OPTIONS SPECIFIC TO PDF/PS/EPS OUTPUT
357 --keep-image-data
358 For SVG documents that reference PNG or JPEG images, include the
359 original, compressed images in the final output, rather than un‐
360 compressed RGB data. This is the default behavior for PDF and
361 (E)PS output.
362
363 --no-keep-image-data
364 Do not include the original, compressed images but instead embed
365 uncompressed RGB date in PDF or (E)PS output. This will most
366 likely result in larger documents that are slower to read.
367
368 MISCELLANEOUS
369 -i object-id, --export-id object-id
370 Allows to specify an SVG object that should be exported based on
371 its XML id attribute. If not specified, all objects will be ex‐
372 ported.
373
374 -u, --unlimited
375 The XML parser has some guards designed to mitigate large CPU or
376 memory consumption in the face of malicious documents. It may
377 also refuse to resolve data: URIs used to embed image data in
378 SVG documents. If you are running into such issues when convert‐
379 ing a SVG, this option allows to turn off these guards.
380
381 --testing
382 For developers only: render images for librsvg's test suite.
383
385 SOURCE_DATE_EPOCH
386 If the selected output format is PDF, this variable can be used
387 to control the CreationDate in the PDF file. This is useful for
388 reproducible output. The environment variable must be set to a
389 decimal number corresponding to a UNIX timestamp, defined as the
390 number of seconds, excluding leap seconds, since 01 Jan 1970
391 00:00:00 UTC. The specification for this can be found at
392 https://reproducible-builds.org/specs/source-date-epoch/
393
394 System language
395 Unless the --accept-language option is specified, the default is
396 to use the system's environment to detect the user's preferred
397 language. This consults the environment variables LANGUAGE,
398 LC_ALL, LC_MESSAGES, and LANG.
399
401 Librsvg source repository and bug tracker:
402 https://gitlab.gnome.org/GNOME/librsvg
403
404 Wiki project page: https://wiki.gnome.org/Projects/LibRsvg
405
406 SVG1.1 specification: http://www.w3.org/TR/SVG11/
407
408 SVG2 specification: http://www.w3.org/TR/SVG2
409
410 GNOME project page: http://www.gnome.org/
411
412
413
414
415 RSVG-CONVERT()