Hi I don't understand your question properly but i think this might help you..
#------------------------------------------------------------------------------- # Calculating the aspect ratio of uploaded profile picture # It compresses the image accordingly.This has been studided # from PIL documentation #------------------------------------------------------------------------------- def handle_uploaded_file(request): """ uploading the image """ profile_pic = request.FILES['profile_image'] poster_wip = Image.open(profile_pic) owidth= poster_wip.size[0] oheight = poster_wip.size[1] if owidth > oheight: if oheight <= 200: pass else: maxSize=(200*owidth/oheight, 200) poster_wip.thumbnail(maxSize, Image.ANTIALIAS) else: if owidth <= 150: pass else: maxSize=(150, 150*oheight/owidth) poster_wip.thumbnail(maxSize, Image.ANTIALIAS) resized_posterFile = StringIO() poster_wip.save(resized_posterFile, "PNG") resized_posterFile.seek(0) posterFile=InMemoryUploadedFile(resized_posterFile, None, str(profile_pic), 'image/jpeg', len(resized_posterFile.getvalue()), None) destination = open(MEDIA_ROOT + '/profile/'+ str(profile_pic), 'wb+') for chunk in posterFile.chunks(): destination.write(chunk) destination.close() return HttpResponse(str(profile_pic)) #------------------------------------------------------------------------------- This is from PIL May be this piece of code can help you. On Sun, Feb 3, 2013 at 10:49 AM, Babatunde Akinyanmi <tundeba...@gmail.com>wrote: > Hi nymo, > I don't know the answer to your question but I can supply some advice. > One good thing about open source is that the source is available for you > to look at. Download one of such apps, look at the source to see how to > creator solved the problem. From there, you can learn a way to do it or get > inspiration to follow a more efficient or elegant route. > > Sent from my Windows Phone > ------------------------------ > From: nYmo > Sent: 2/2/2013 9:44 PM > To: django-users@googlegroups.com > Subject: On the fly image resize > > Hi all, > I'm new to django and also python but have already some programming > experience. I'm currently creating my first application in django and get > stucked because I'm looking for the best way to resize uploaded images. > I'm already so far that I can upload/delete/update my images and show them > in my view. Now I want to resize the images for my view and thought about > the best way? > > First question: Is it possible to resize the images on the fly? For > example I uploaded an image in 1920x1080px and now want to transform it to > 400x200 or something similar when the view is being loaded? Is this a > convenient way in django or not? > > The only other way in my opinion could be to resize the image during the > file is being uploaded. What I don't like about this is that I have more > than one copy of one image only because of different image sizes. > > Any other thoughs? > > I know that there are some nice packages out there where such problems are > already solved. But since I'm new to django I want to learn by myself how > to accomplish the basic stufff :) > > Thanks in advance > > Regards nymo > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- Regards Nikhil Verma +91-958-273-3156 -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.