如何将枕头 EPS 调整为 JPG 质量 [英] How to adjust Pillow EPS to JPG quality

查看:56
本文介绍了如何将枕头 EPS 调整为 JPG 质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Pillow 将 EPS 图像转换为 JPEG.但结果是低质量的.我正在尝试使用 resize 方法,但它被完全忽略了.我将 JPEG 图像的大小设置为 (3600, 4700),但结果图像具有 (360, 470) 大小.我的代码是:

I'm trying to convert EPS images to JPEG using Pillow. But the results are of low quality. I'm trying to use resize method, but it gets completely ignored. I set up the size of JPEG image as (3600, 4700), but the resulted image has (360, 470) size. My code is:

eps_image = Image.open('img.eps')
height = eps_image.height * 10
width = eps_image.width * 10
new_size = (height, width)
print(new_size)  # prints (3600, 4700)
eps_image.resize(new_size, Image.ANTIALIAS)
eps_image.save(
    'img.jpeg',
    format='JPEG'
    dpi=(9000, 9000),
    quality=95)

UPD. Vasu Deo.S 注意到了我的一个错误,多亏了他,JPG 图像变得更大了,但质量仍然很低.我为 resize 函数尝试了不同的 DPI、大小、重采样值,但结果没有太大变化.我怎样才能让它变得更好?

UPD. Vasu Deo.S noticed one my error, and thanks to him the JPG image has become bigger, but quality is still low. I've tried different DPI, sizes, resample values for resize function, but the result does not change much. How can i make it better?

推荐答案

问题在于 PIL 是一个光栅图像处理器,而不是一个矢量图像处理器.它在打开时将矢量图像(例如您的 EPS 文件和 SVG 文件)光栅化" 到网格上,因为它只能处理光栅.

The problem is that PIL is a raster image processor, as opposed to a vector image processor. It "rasterises" vector images (such as your EPS file and SVG files) onto a grid when it opens them because it can only deal with rasters.

如果该网格没有足够的分辨率,您将永远无法重新获得它.通常,它以 100dpi 进行光栅化,因此如果您想制作更大的图像,您甚至需要在开始之前将其光栅化到更大的网格上.

If that grid doesn't have enough resolution, you can never regain it. Normally, it rasterises at 100dpi, so if you want to make bigger images, you need to rasterise onto a larger grid before you even get started.

比较:

from PIL import Image

eps_image = Image.open('image.eps')
eps_image.save('a.jpg')

结果为 540x720:

The result is 540x720:

还有这个:

from PIL import Image

eps_image = Image.open('image.eps')
# Rasterise onto 4x higher resolution grid
eps_image.load(scale=4)   
eps_image.save('a.jpg') 

结果为 2160x2880:

The result is 2160x2880:

您现在有足够的质量来随意调整大小.

You now have enough quality to resize however you like.

请注意,您根本不需要编写任何 Python 来执行此操作 - ImageMagick 将为您完成所有操作.它包含在大多数 Linux 发行版中,可用于 macOS 和 Windows,您只需在终端中使用它.等价的命令是这样的:

Note that you don't need to write any Python to do this at all - ImageMagick will do it all for you. It is included in most Linux distros and is available for macOS and Windows and you just use it in Terminal. The equivalent command is like this:

magick -density 400 input.eps -resize 800x600 -quality 95  output.jpg

这篇关于如何将枕头 EPS 调整为 JPG 质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆