以下是来自 Wikipedia 的 SVG 图像:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 193.13333 47.626667"
height="47.626667"
width="193.13333"
xml:space="preserve"
id="svg2"
version="1.1"><metadata
id="metadata8"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
id="defs6" /><g
transform="matrix(1.3333333,0,0,-1.3333333,0,47.626667)"
id="g10"><g
transform="scale(0.1)"
id="g12"><path
id="path14"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="M 1.41797,1.41797 H 1135.27 l 311.8,177.07803 -311.8,177.266 H 1.41797 V 1.41797 v 0" /><path
id="path16"
style="fill:none;stroke:#231f20;stroke-width:2.83500004;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 1.41797,1.41797 H 1135.27 l 311.8,177.07803 -311.8,177.266 H 1.41797 V 1.41797 v 0" /><path
id="path18"
style="fill:#1a67bb;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="M 22.6563,22.6953 H 1129.62 L 1291.15,178.535 1129.62,334.488 H 22.6563 V 22.6953" /><path
id="path20"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m 247.367,93.5742 h 117.106 v 25.2738 h -82.692 l 81.289,147.277 v 25.848 H 249.922 v -25.274 h 77.043 L 247.367,121.402 v -27.8278 0" /><path
id="path22"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m 406.738,266.699 h 25.02 v 29.844 h -25.02 v -29.844 0" /><path
id="path24"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m 453.359,266.699 h 25.02 v 29.844 h -25.02 v -29.844 0" /><path
id="path26"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="M 470.137,93.5742 H 498 v 0 c -0.289,4.2461 -0.578,8.7888 -0.867,13.6448 -0.285,4.539 -0.285,9.363 -0.285,14.183 v 0 117.973 h -29.559 v -85.535 0 c 0,-11.379 -2.266,-20.485 -6.512,-27.289 -4.289,-6.844 -11.379,-10.262 -20.773,-10.262 -7.668,0 -13.07,2.559 -16.777,7.672 -3.672,5.144 -5.688,13.387 -5.688,24.73 v 0 90.684 h -29.555 v -97.488 0 c 0,-15.336 3.418,-27.582 10.223,-36.68 6.844,-9.0742 17.637,-13.6132 32.438,-13.6132 9.937,0 17.89,2.2343 23.867,7.0976 5.687,4.5316 10.226,10.2146 13.929,17.0236 v 0 h 0.579 l 1.117,-22.1408 v 0" /><path
id="path28"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m 539.867,93.5742 h 29.559 v 78.4418 c 0,7.382 0.863,13.648 2.551,19.047 1.695,5.402 4,9.683 6.808,13.07 2.84,3.129 6.266,5.687 9.969,7.414 3.672,1.402 7.344,2.266 11.629,2.266 1.691,0 3.383,0 4.824,-0.29 1.406,-0.285 3.133,-0.574 4.535,-0.863 v 0 28.442 0 c -0.578,0 -1.113,0 -1.402,0.289 -0.289,0 -0.863,0 -1.442,0 -5.398,0 -10.222,-0.575 -14.472,-2.016 -4.246,-1.406 -7.664,-3.383 -10.801,-5.941 -3.094,-2.555 -5.937,-5.403 -8.242,-8.532 -2.27,-3.129 -4.246,-6.554 -5.653,-10.257 v 0 h -0.578 v 0 c 0,1.152 0,2.839 0,5.144 -0.285,2.27 -0.285,4.824 -0.574,7.383 -0.289,2.555 -0.289,4.82 -0.289,7.09 C 566,236.527 566,238.258 566,239.375 v 0 h -27.285 v 0 c 0.289,-4.246 0.578,-8.785 0.867,-13.355 0.285,-4.825 0.285,-9.649 0.285,-14.473 v 0 -117.9728 0" /><path
id="path30"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m 632.422,93.5742 h 29.555 V 239.375 h -29.555 v -145.8008 0" /><path
id="path32"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m 631.559,268.676 h 31.285 v 31.539 h -31.285 v -31.539 0" /><path
id="path34"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m 794.707,97.5391 -1.687,25.0159 v 0 c -3.137,-1.981 -7.415,-3.707 -12.239,-5.114 -4.824,-1.433 -9.941,-2.265 -14.793,-2.265 -12.785,0 -22.433,4.531 -29.269,13.64 -7.098,9.075 -10.516,21.317 -10.516,36.653 0,17.926 3.418,30.996 10.223,39.527 6.847,8.527 16.484,12.777 29.015,12.777 5.399,0 10.223,-0.539 14.473,-1.976 4.285,-1.406 7.957,-2.848 11.668,-4.824 v 0 l 1.438,24.73 v 0 c -3.711,1.402 -7.989,2.844 -13.391,3.961 -5.399,1.152 -10.801,1.727 -16.199,1.727 -11.094,0 -21.028,-1.727 -29.563,-5.399 -8.531,-3.711 -15.621,-9.105 -21.308,-15.66 -5.688,-6.809 -9.969,-14.762 -12.778,-24.156 -2.847,-9.36 -4.289,-19.336 -4.289,-30.418 0,-10.227 1.442,-19.914 4,-28.985 2.555,-9.105 6.801,-17.066 12.203,-23.621 5.399,-6.511 12.243,-11.914 20.778,-15.6129 8.242,-3.9649 18.172,-5.9453 29.55,-5.9453 6.27,0 12.207,0.5742 18.184,1.7265 5.977,1.3672 10.801,2.8125 14.5,4.2188 v 0" /><path
id="path36"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m 822.824,93.5742 h 29.559 v 86.4028 c 0,11.375 2.265,20.484 7.129,26.996 4.531,6.55 11.379,9.687 20.734,9.687 7.664,0 13.067,-2.558 16.777,-7.672 3.418,-5.144 5.118,-13.386 5.118,-24.73 v 0 -90.6838 h 29.55 v 97.4888 0 c 0,15.332 -3.378,27.574 -10.226,36.679 -6.809,9.074 -17.598,13.649 -32.402,13.649 -9.676,0 -17.344,-2.27 -22.743,-6.551 -5.695,-4.539 -10.226,-9.363 -13.359,-14.797 v 0 h -0.578 v 86.723 h -29.559 v -213.1918 0" /></g></g></svg>
以下命令分别成功将其转换为 2000×493 和 406×100 像素的 PNG:
inkscape -w 2000 input.svg -o output.png
inkscape -h 100 input.svg -o output.png
但是如果我同时指定宽度和高度(-w 2000 -h 100
),则会强制使用这两个值,因此生成的图像会扭曲(2000×100 像素)。
是否可以以这样一种方式指定它们,使它们作为“盒子”应用,即,
inkscape -w 2000 -h 100 input.svg -o output.png
应生成 2000×493 像素的图像inkscape -w 100 -h 2000 input.svg -o output.png
应生成 100×25 像素的图像
自 2024 年起,Inkscape 没有选项可以维持原始纵横比(根据此问题)。
相反,使用
输出的宽度不会超过 2000px,高度不会超过 100px,并且不会被“拉伸”或“挤压”。