sorl-thumbnail:编写图像文件时的编码器错误-2 [英] sorl-thumbnail: encoder error -2 when writing image file

查看:232
本文介绍了sorl-thumbnail:编写图像文件时的编码器错误-2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用sorl-thumbnail一段时间没有问题。但是,以下错误开始出现:编写图像文件时的编码器错误-2

I've been using sorl-thumbnail for some time without problems. However, the following error started to appear: encoder error -2 when writing image file.

以下代码导致错误:

from sorl.thumbnail import get_thumbnail
photobooth_thumbnail = get_thumbnail(img_file,
    PHOTOBOOTH_THUMB_SIZE, crop='center', quality=99)

正在 img_file 一个Django模型的ImageField,当 PHOTOBOOTH_THUMB_SIZE 是足够大时。当我使用 PHOTOBOOTH_THUMB_SIZE ='670'时,一切正常,但当我将其增加到 PHOTOBOOTH_THUMB_SIZE ='1280',出现上述错误。

being img_file a Django models' ImageField and when PHOTOBOOTH_THUMB_SIZE is "sufficiently large". When I was using PHOTOBOOTH_THUMB_SIZE = '670', everything worked just fine, but when I increased it to PHOTOBOOTH_THUMB_SIZE = '1280', the aforementioned error appeared.

我怀疑这是PIL中的错误,而不是在sorl-thumbnail中,给定低级消息。我想要更大的缩略图,所以我很乐意为此提供任何帮助。感谢提前。

I'm suspecting this is an error in PIL rather than in sorl-thumbnail, given the low level message. I'd like to have bigger thumbnails, so I'd appreciate any help on this. Thanks in advance.

推荐答案

我最后补丁文件 pil_engine.py /lib/python2.7/site-packages/sorl/thumbnail/engines

--- pil_engine.py   2013-09-09 03:58:27.000000000 +0000
+++ pil_engine_new.py   2013-11-05 21:19:15.053034383 +0000
@@ -79,6 +79,7 @@
             image.save(buf, **params)
         except IOError:
             params.pop('optimize')
+            ImageFile.MAXBLOCK = image.size[0] * image.size[1]
             image.save(buf, **params)
         raw_data = buf.getvalue()
         buf.close()

这解决了我的问题。

这篇关于sorl-thumbnail:编写图像文件时的编码器错误-2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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