1
我使用django-cumulus将我的媒体存储在Rackspace云中。django-cumulus:从django.db.models.ImageField检索PIL.Image对象
我需要从ImageField检索数据到PIL.Image。我需要它对这个图像进行一些修改(裁剪,过滤器等),并将其保存到另一个积云ImageField。
我试过这段代码:
def field_to_image(field):
# field - cumulus-powered ImageField on some model
from StringIO import StringIO
from PIL import Image
r = field.read() # ERROR throws here!
image = Image.open(StringIO(r))
return image
它的工作对我的档案一半好,但对另一半我总是收到此错误:
Traceback (most recent call last):
File "tmp.py", line 78, in <module>
resize_photos(start)
File "tmp.py", line 59, in resize_photos
photo.make_thumbs()
File "/hosting/site/news/models.py", line 65, in make_thumbs
i = functions.field_to_image(self.img)
File "/hosting/site/functions.py", line 169, in field_to_image
r = field.read()
File "/usr/local/lib/python2.7/dist-packages/cumulus/storage.py", line 352, in read
if self._pos == self._get_size() or chunk_size == 0:
File "/usr/local/lib/python2.7/dist-packages/cumulus/storage.py", line 322, in _get_size
self._size = self._storage.size(self.name)
File "/usr/local/lib/python2.7/dist-packages/cumulus/storage.py", line 244, in size
return self._get_object(name).total_bytes
AttributeError: 'bool' object has no attribute 'total_bytes'
谁能帮助我?也许有更好的方法从rackspace检索PIL.Image对象?
的文件,我想读()存在并且可透过网址上Rackspace公司
它已经返回一个'django.core.files.images.ImageFile'对象。你想做什么? – codingjoe