The Imagefile is just a pointer to file. Here is what I do to upload
and resize an image. I hope it helps.

        file_to_open = settings.MEDIA_ROOT+'//profiles//'+
user.username+'-'+file.name
        fd = open(file_to_open, 'wb+')
        if file.multiple_chunks():
            for chunk in file.chunks():
                fd.write(chunk)
        else:
            fd.write(file.read())
        fd.close()

        # Resize the image
        ms = Image.open(file_to_open)
        size = 145,132
        ms.thumbnail(size, Image.ANTIALIAS)
        ms.save(file_to_open, "JPEG")

On Mar 18, 10:03 am, Alex Robbins <alexander.j.robb...@gmail.com>
wrote:
> I think Satchmo useshttp://code.google.com/p/sorl-thumbnail/
> I think it uses PIL underneath a layer of abstraction. That might work
> for you if you are just wanting to generate alternate versions of
> uploaded images.
>
> Alex
>
> On Mar 18, 12:10 am, robinne <develo...@computer-shoppe.net> wrote:
>
> > I can save an uploaded image to a FileField like this (where
> > "ProductFile" is a model) and "TempFile" is an ImageField:
>
> > uploadedfile = request.FILES['uploadfile']
> > ProductFile.objects.create(FileName=UploadDate=datetime.datetime.now(),
> > TempFile=uploadedfile)
>
> > But, how do I manipulate the image size and then save to this model? I
> > am working with PIL, but I can't save a PIL Image to a ImageField. Can
> > I save the file to disk using PIL and then pass in the file path and
> > name to the model? If so, what is the syntax for saving the ImageFile
> > when you are no longer working with the original uploadedfile object?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to