Monday, 9 September 2013

Downloading Image with urllib.urlretrieve() in Django

Downloading Image with urllib.urlretrieve() in Django

I've been attempting to work at this for hours but decided to turn to the
experts here on stackoverflow.
I'm trying to download an image from a url:
import urllib
originalphoto = urllib.urlretrieve(bundle.obj.url)
#originalphoto is being saved to the tmp directory in Ubuntu
This works and it saves the image in the tmp directory, but I need to
modify this image by resizing it to a 250px by 250px image and then save
it to a folder on my Desktop: /home/ubuntu/Desktop/resizedshots
The name of the original image is in bundle.obj.url, for example if
bundle.obj.url is:
http://photographs.500px.com/kyle/09-09-201315-47-571378756077.jpg the
name of the image is "09-09-201315-47-571378756077.jpg"
After the image is resized, I need to save is to this folder as
09-09-201315-47-571378756077small.jpg
As you can see, I'm adding in the word "small" to the end the file name.
Once all of this is done, I would like to delete the temporary image file
that was downloaded so that it doesn't take up the disk.
Any ideas on how this can be done?
Thanks

No comments:

Post a Comment