在 python 中使用 cairosvg 模块时可以指定缩放比例吗
Can I specify scaling when using the cairosvg module inside of python
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
在 Python 脚本中使用 cairosvg2png
时如何指定比例因子?
文档已更新于:http://cairosvg.org/documentation/ with API documentation commit
我有同样的问题 - 文档没有明确说明这一点,但事实证明,它就像将 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)
这对我来说绝对适用于 2.0.3 版。
在此commit 添加了 2 个新参数。
[... other params]
output_width=None,
output_height=None
对我来说 output_height
和 output_width
完成了工作。
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
在 Python 脚本中使用 cairosvg2png
时如何指定比例因子?
文档已更新于:http://cairosvg.org/documentation/ with API documentation commit
我有同样的问题 - 文档没有明确说明这一点,但事实证明,它就像将 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)
这对我来说绝对适用于 2.0.3 版。
在此commit 添加了 2 个新参数。
[... other params]
output_width=None,
output_height=None
对我来说 output_height
和 output_width
完成了工作。