【发布时间】:2015-10-24 13:02:09
【问题描述】:
我之前问过一个相对的问题,关于pillow。
Python Pillow: Make image progressive before sending to 3rd party server
只是为了扩展这一点,当我上传图像并将其存储在服务器上时,如何将progressiveness 放入图像中?
模型.py
>class Blog(models.Model):
banner = models.FileField("banner", upload_to='blog_banner', help_text='Upload blog banner', blank=True, null=True)
Forms.py
>def clean(self):
data = self.cleaned_data
banner = data['banner']
# Check and make banner image progressive
if not Utils.is_progressive_img(banner):
data['banner'] = Utils.make_progressive_img(banner)
渐进法
img = Image.open(source)
progressive_img = StringIO()
img.save(progressive_img, "JPEG", quality=80, optimize=True, progressive=True)
在forms.py 中,当我保存博客文章时,我看到以下错误,我知道这是由于StringIO() 的格式造成的
错误
AttributeError at /blog/create/
StringIO instance has no attribute '_committed'
【问题讨论】:
-
我也有这个错误,看看这个答案也许会有所帮助(注意在python3中没有StringIO ...而是BytesIO ...但是想法应该是一样的)stackoverflow.com/a/30435175/3033586
标签: python django models filefield stringio