开发者

Django/Python resize image

I have a image from

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

and i want to know it's size and possibly re开发者_JAVA技巧size 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.


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')


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


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


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜