【发布时间】:2016-11-05 05:03:11
【问题描述】:
我正在使用 Python Wand 模块(版本 0.4.3。)将存储在 pdf 中的图像转换为 PNG。当我以原始图像的宽度和高度保存最终图像时,最终的 PNG 质量非常好。但是,当我尝试将其保存为较小的图像时,最终的 PNG 会变得模糊,质量也不是那么好。
两个图像之间的差异显示为here。顶部图像转换为原始尺寸 (10800x7200px)。第二个是缩放到 1250x833px。
有什么办法可以改善第二张图片吗?我使用了不同的滤镜和模糊设置。但是,无法获得我想要的图像质量。任何帮助是极大的赞赏。
我用来将 PDF 转换为原始大小的 png 的代码:
def pdf_to_png(pdf_name, res):
with Image(filename=pdf_name, resolution=res) as img:
with Image(width=img.width,height=img.height, background=Color("white")) as bg:
bg.composite(img,0,0)`
bg.save(filename="Drawing_improved_wand.png")`
pdf_to_png('Drawing_1.pdf', 300)
调整png大小的代码:
with Image(filename="Drawing_1.pdf", resolution=(300,300)) as img:
with Image(width=1250, height=833, background=Color("white")) as bg:
img.resize(1250, 833,filter='undefined', blur=1)
img.format = 'png'
bg.composite(img,0,0)
bg.save(filename='Drawing_improved_wand1250x833.png')
【问题讨论】: