简体   繁体   English

Django / Python调整大小图像

[英]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 resize it. 我想知道它的大小,并可能调整它的大小。 How i can do it? 我该怎么办?

thanks. 谢谢。

UPD UPD

before. 之前。 i read() file and gave this string and some info? 我读了()文件,并给了这个字符串和一些信息? to SQL function. 到SQL函数。 And she save it on ftp. 她将其保存在ftp上。

how i can get data same as the data returned from read() method? 我如何获取与read()方法返回的数据相同的数据?

i try to use Image.tostring() 我尝试使用Image.tostring()

and save it. 并保存。 But i have 0x0px image. 但是我有0x0px图像。

Here is a small snippet from one of my web applications (sightly modified), which creates a thumbnail with the maximum size of 200x200 pixels. 这是我的一个Web应用程序中的一小段代码(经过明显修改),它创建了最大尺寸为200x200像素的缩略图。 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 . 您可以使用PIL处理图像。 http://www.pythonware.com/products/pil/ http://www.pythonware.com/products/pil/

If you would like to add "automated image processing" to your project, you might consider using Django-imagekit . 如果您想在项目中添加“自动图像处理”,则可以考虑使用Django-imagekit

The author has included Installion and usage instructions on this Github Repo page . 作者在Github Repo页面上包含了安装和使用说明。

Hope this helps you as I found it from the same search as I found this Question :) 希望这对您有所帮助,因为我从与发现此问题相同的搜索中找到了它:)

用户可用的缩略图库之一,例如http://djangothumbnails.com/或更多http://code.djangoproject.com/wiki/ThumbNails

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM