python - 压缩的头像图片在Python中变得“旋转”

标签 python django compression python-imaging-library

我在应用程序中添加了Avatar的图像压缩代码。
但有时会将上载的图片保存为“旋转”。

请检查以下代码,

import Image, ImageFile  
pic = "pic/goes/here.jpg"

im = Image.open(pic)

width, height = im.size
if width > 1000 or height > 1000:
    width = width*.7
    height = height*.7

im = im.resize((int(math.floor(width)), int(math.floor(height))), Image.ANTIALIAS)
try:
    im.save(pic,optimize=True,quality=70)

except IOError:
    ImageFile.MAXBLOCK = width * height
    im.save(pic,optimize=True,quality=70)


我是否需要更新某些内容或其他替代方法来调整AVATAR的图片上传尺寸?谢谢!

最佳答案

请更改quality = 70并尝试。

我发现85在我的6-10mb文件中没有区别,而65是合理的最低数字。

关于python - 压缩的头像图片在Python中变得“旋转”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46883353/

相关文章:

python - 定义跨多个模型的关系 - Django

iphone - 如何跳过压缩一张 PNG?

python - 使用生成器循环遍历列表中的数字

python - 如何使用正则表达式回溯捕获括号之间的多个匹配

python - 如何将多个数据框写入一张 Excel 工作表?

python - 值错误 : Invalid RGBA argument: What is causing this error?

django - Django 是否应该自己实现 DB on_delete 规则?

django - 避免 makemigrations 重新创建日期字段

cryptography - 7-zip 如何检查您提供的密码是否正确?

c# - SharpZipLib 的基础知识。我错过了什么?