0

I have a image from

files = request.FILES['new_photo'].read()

and i want to know it's size and possibly resize it. How i can do it?

thanks.

UPD

before. i read() file and gave this string and some info? to SQL function. And she save it on ftp.

how i can get data same as the data returned from read() method?

i try to use Image.tostring()

and save it. But i have 0x0px image.

4 Answers 4

5

Here is a small snippet from one of my web applications (sightly modified), which creates a thumbnail with the maximum size of 200x200 pixels. Maybe you can use some parts of it:

from PIL import Image

image = request.FILES['new_photo']
if image:
    img = Image.open(image)
    img.save(path.join(app.config['UPLOAD_FOLDER'],
        secure_filename('upload-%d.jpg' % self.obj.id)), 'JPEG')
    img.thumbnail((200, 200), Image.ANTIALIAS)
    img.save(path.join(app.config['UPLOAD_FOLDER'],
        secure_filename('upload-%d.200.jpg' % self.obj.id)), 'JPEG')
Sign up to request clarification or add additional context in comments.

Comments

2

you can use PIL for processing images . http://www.pythonware.com/products/pil/

2 Comments

Yes. But how? i don't don't know image size. and function like fromString() have size argument
use StringIO: img = Image.open(StringIO(files)) after which: img.size contains the size of the image.
0

User one of the thumbnail libraries available such as http://djangothumbnails.com/ or more http://code.djangoproject.com/wiki/ThumbNails

Comments

0

If you would like to add "automated image processing" to your project, you might consider using Django-imagekit.

The author has included Installion and usage instructions on this Github Repo page.

Hope this helps you as I found it from the same search as I found this Question :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.