is it possible to manipulate image in PIL after uploading directly by its "request.FILES.GETLIST(FORMFIELD)" address not the saved picture on hard disk

70 views
Skip to first unread message

ali Eblice

unread,
Aug 26, 2016, 11:46:02 AM8/26/16
to Django users
Hello Friends
is it possible to manipulate image in PIL after uploading directly by its "request.FILES.GETLIST(FORMFIELD)"  address not the saved picture on hard disk?

I wrote a function for manipulating  but its only working with  " Image.open('a.jpg') " but i don't want to save image after uploading and then opening it for manipulating , is it possible to manipulate image with its "request.FILES" object address?

Asad Jibran Ahmed

unread,
Aug 26, 2016, 12:05:21 PM8/26/16
to django...@googlegroups.com
Hi,
 Every object in `request.FILES` is actually a file *liike* object that you can use for processing. I guess you can use something like `PIL.Image.frombytes` with the `request.FILES[filename].read()` data.

Pillow (PIL Fork) documentation for the `frombytes` method: https://pillow.readthedocs.io/en/3.3.x/reference/Image.html#PIL.Image.frombytes

Hope that helps.
Regards,

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9b6734c8-4530-42b3-b791-99bbce020b32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ali Eblice

unread,
Sep 10, 2016, 4:04:45 AM9/10/16
to Django users
thanks for answering
with your help solved the problem
if any one get to this problem, here is how i solved it:

            filelist = request.FILES.getlist('uploadimage')   #first get list of your uploaded file object as list
            for imgfile in filelist:                                       # iterate over your list and give each uploaded photo object to your PIL
                  img = Image.open(imgfile)                       # you can open your uploaded photo object as normal picture like this
                  #your manipulation and changes on picture comes here
                  img.save('MypicName.jpeg')  #finaly save your picture like this


On Friday, August 26, 2016 at 8:35:21 PM UTC+4:30, Asad Jibran Ahmed wrote:
Hi,
 Every object in `request.FILES` is actually a file *liike* object that you can use for processing. I guess you can use something like `PIL.Image.frombytes` with the `request.FILES[filename].read()` data.

Pillow (PIL Fork) documentation for the `frombytes` method: https://pillow.readthedocs.io/en/3.3.x/reference/Image.html#PIL.Image.frombytes

Hope that helps.
Regards,
On Fri, Aug 26, 2016 at 7:46 PM, ali Eblice <alie...@gmail.com> wrote:
Hello Friends
is it possible to manipulate image in PIL after uploading directly by its "request.FILES.GETLIST(FORMFIELD)"  address not the saved picture on hard disk?

I wrote a function for manipulating  but its only working with  " Image.open('a.jpg') " but i don't want to save image after uploading and then opening it for manipulating , is it possible to manipulate image with its "request.FILES" object address?

--
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...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages