Hi there
I am saving a image path to my model image field with custom save function. then i realised that I am just saving the path and not an actual object. my question is how to convert that path to a object using PIL.
Hi there
I am saving a image path to my model image field with custom save function. then i realised that I am just saving the path and not an actual object. my question is how to convert that path to a object using PIL.
how to convert that path to a object using PIL
If by object you mean reading the image using PIL then you can do the following:
from PIL import Image
image = Image.open(<path>)
I don't know how if you mean something else.
The image saved correctly with urllib.urlretrieve(image_name, image_path). then i want to do a
Image.open(image_path)
but get the error:
AttributeError at /admin/featured/item/6/
_committed
Request Method: POST
Request URL: http://localhost:8000/admin/featured/item/6/
Django Version: 1.3 pre-alpha SVN-13431
Exception Type: AttributeError
Exception Value:
_committed
Exception Location: /Library/Python/2.6/site-packages/PIL/Image.py in __getattr__, line 512
Python Executable: /usr/bin/python
Python Version: 2.6.1
this is my code
regex = re.compile(r"^(http://)?(www\.)?(youtube\.com/watch\?v=)?(?P<id>[A-Za-z0-9\-=_]{11})")
match = regex.match(self.link)
if not match:
video_id = ''
video_id = match.group('id')
img_url = 'http://img.youtube.com/vi/%s/0.jpg' % video_id
urllib.urlretrieve(img_url, os.path.join(settings.MEDIA_ROOT, 'featured/%s.jpg' % video_id))
image = Image.open(os.path.join(settings.MEDIA_ROOT, 'featured/%s.jpg' % video_id))
self.image=image
super(Item, self).save()