Форум сайта python.su
0
Hi всем.
Кто то встречался с такой ошибкой (возникает при аплоаде картинки )
"
IOError at /users/a1/
cannot identify image file
Request Method: POST
Request URL: http://127.0.0.1:8000/users/a1/
Exception Type: IOError
Exception Value:
cannot identify image file
Exception Location: /usr/lib/python2.5/site-packages/PIL/Image.py in open, line 1917
Python Executable: /usr/bin/python2.5
Python Version: 2.5.4
"
также если делать через ipython:
# im =Image.open(StringIO('/media/disk/FOTO/P1010003111.JPG'))
то такая же ошибка :
"
In [8]: i =Image.open(StringIO('/media/disk/FOTO/P1010003111.JPG'))
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
/home/r/PROJECTS/django/mysite/<ipython console> in <module>()
/usr/lib/python2.5/site-packages/PIL/Image.pyc in open(fp, mode)
1915 pass
1916
-> 1917 raise IOError("cannot identify image file")
1918
1919 #
IOError: cannot identify image file
"
Отредактировано (Май 10, 2009 00:57:36)
Офлайн
0
Аналогично ругаеться…
Exception Type: IOError
Exception Value:
(2, 'No such file or directory')
Exception Location: /usr/lib/python2.6/dist-packages/PIL/Image.py in open, line 1889
Python Executable: /usr/bin/python
Python Version: 2.6.2
Python Path:
/home/xfree/Python/djcode/imagecms/../imagecms/cms/models.py in save
12. from django.core.files.uploadedfile import SimpleUploadedFile
13.
14. # Set our max thumbnail size in a tuple (max width, max height)
15. THUMBNAIL_SIZE = (50, 50)
16.
17. # Open original photo which we want to thumbnail using PIL's Image
18. # object
19. image = Image.open(self.photo.name)
from django.db import models
from django.contrib import admin
class Photo(models.Model):
title = models.CharField(max_length=50)
photo = models.ImageField(upload_to="photos")
thumbnail = models.ImageField(upload_to="thumbnails/", editable=False)
def save(self):
from PIL import Image
from cStringIO import StringIO
from django.core.files.uploadedfile import SimpleUploadedFile
# Set our max thumbnail size in a tuple (max width, max height)
THUMBNAIL_SIZE = (50, 50)
# Open original photo which we want to thumbnail using PIL's Image
# object
image = Image.open(self.photo.name)
# Convert to RGB if necessary
# Thanks to Limodou on DjangoSnippets.org
# http://www.djangosnippets.org/snippets/20/
if image.mode not in ('L', 'RGB'):
image = image.convert('RGB')
# We use our PIL Image object to create the thumbnail, which already
# has a thumbnail() convenience method that contrains proportions.
# Additionally, we use Image.ANTIALIAS to make the image look better.
# Without antialiasing the image pattern artifacts may result.
image.thumbnail(THUMBNAIL_SIZE, Image.ANTIALIAS)
# Save the thumbnail
temp_handle = StringIO()
image.save(temp_handle, 'png')
temp_handle.seek(0)
# Save to the thumbnail field
suf = SimpleUploadedFile(os.path.split(self.photo.name)[-1],
temp_handle.read(), content_type='image/png')
self.thunbnail.save(suf.name+'.png', suf, save=False)
# Save this photo instance
super(Photo, self).save()
class PhotoAdmin(admin.ModelAdmin):
list_display = ('title', 'photo', 'thumbnail')
search_fields = ('title', 'photo')
list_filter = ('title', 'photo')
admin.site.register(Photo, PhotoAdmin)
Отредактировано (Сен. 28, 2009 18:01:08)
Офлайн
2
Ром, в чем вопрос?
Ты не правильно работаешь с картинкой. Читай документацию.
И начни наконец отлаживать код прежде чем постить в форум.
Офлайн
41
romankrv
пил небось не из репозитория бубунты
Офлайн
0
Скорее всего оно. Я не ставил отдельно pil.
А что есть проблема с этой версией из репо?
Офлайн