mcw*_*ard 5 python svg png cairo
cairosvg 的命令行版本允许缩放。这是帮助函数的输出:
cairosvg -h
usage: cairosvg [-h] [-v] [-f {pdf,png,ps,svg}] [-d DPI] [-W WIDTH]
[-H HEIGHT] [-s SCALE] [-u] [-o OUTPUT]
input
CairoSVG - A simple SVG converter based on Cairo.
positional arguments:
input input filename or URL
optional arguments:
-h, --help show this help message and exit
-v, --version show program\'s version number and exit
-f {pdf,png,ps,svg}, --format {pdf,png,ps,svg}
output format
-d DPI, --dpi DPI ratio between 1 inch and 1 pixel
-W WIDTH, --width WIDTH
width of the parent container in pixels
-H HEIGHT, --height HEIGHT
height of the parent container in pixels
-s SCALE, --scale SCALE
output scaling factor
Run Code Online (Sandbox Code Playgroud)
另请参阅cairosvg 文档
cairosvg2png在Python 脚本内部使用时如何指定缩放因子?
我有同样的问题 - 文档没有明确说明这一点,但事实证明,它就像将scale=2.0关键字参数传递给svg2png方法一样简单。
import cairosvg
input_fn = '/home/me/input.svg'
output_fn = '/home/me/output.png'
cairosvg.svg2png(url=input_fn, write_to=output_fn, scale=2.0)
Run Code Online (Sandbox Code Playgroud)
这在 2.0.3 版本上绝对适合我。
小智 4
在此提交中添加了 2 个新参数。
[... other params]
output_width=None,
output_height=None
Run Code Online (Sandbox Code Playgroud)
对我来说output_height,output_width完成了这项工作。