我正在try 在Python中将SVG转换为PNG,但我不想要任何压缩和抗锯齿. 我try 对子进程使用Inkscape,但我找不到参数来告诉Inkscape我不想要任何压缩和反色调.
inkscape_path = "D:/Programmes/bin/inkscape.exe"
dpi_value = 300
result = subprocess.run([inkscape_path, "cleaned.svg", "--export-id=layer1", "--export-ignore-filters", "--export-type=png", "--export-filename=" + "cleaned.png", "--export-dpi=" + str(dpi_value)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode != 0:
print("Error: " + result.stderr.decode("utf-8"))
else:
print("PNG file exported successfully.")
我也试过用魔杖,但仍然有抗锯齿,尽管如此.antialisaing=False:
# Load SVG file as an image object
with Image(filename='cleaned.svg') as img:
# Disable antialiasing
library.MagickSetOption(img.wand, b'antialias', b'0')
img.antialias = False
# Convert image format to PNG
img.format = 'png'
# Save without compression
img.compression_quality = 100
# Save to 300 dpi
img.resolution = (300, 300)
# Save output file
img.save(filename='cleaned.png')
在导出过程中,我们可以在Inkscape的UI中指定这一点,您知道我们是否可以在Python中使用子进程或库来做同样的事情?