Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ImageOps.fit正在模糊我的图像_Python_Image_Python Imaging Library - Fatal编程技术网

Python ImageOps.fit正在模糊我的图像

Python ImageOps.fit正在模糊我的图像,python,image,python-imaging-library,Python,Image,Python Imaging Library,我正在使用ImageOps调整上传的头像图像的大小和中心位置。问题是,当我试图上传一个已经达到所需大小的图像时,上传的图像会变得模糊 有关守则: avatar_size = (59,59) #resized_im = im.resize(avatar_size, Image.ANTIALIAS) #This works! But doesn't crop. formatted_im = ImageOps.fit(im, avatar_size, Image.ANTIALIAS, center

我正在使用ImageOps调整上传的头像图像的大小和中心位置。问题是,当我试图上传一个已经达到所需大小的图像时,上传的图像会变得模糊

有关守则:

avatar_size = (59,59)
#resized_im = im.resize(avatar_size, Image.ANTIALIAS)   #This works! But doesn't crop.
formatted_im = ImageOps.fit(im, avatar_size, Image.ANTIALIAS, centering=(0.5,0.5))     
formatted_im.save('foo.jpg', 'JPEG', quality=95)

因此,当我上传一个59x59px图像时,服务器上的上传结果会变得模糊。尝试过谷歌搜索、阅读文档和实验,但无法解决这个问题。谢谢你的帮助。

可能是抗锯齿造成了模糊。 试试看怎么样:

avatar_size = (59,59)
method = Image.NEAREST if im.size == avatar_size else Image.ANTIALIAS
formatted_im = ImageOps.fit(im, avatar_size, method = method, centering = (0.5,0.5)) 
formatted_im.save('foo.jpg', 'JPEG', quality=95)

工作得很有魅力。非常感谢。