简体   繁体   English

Django在发送给客户端之前调整图像大小

[英]Django resize image before sending to client

I have the following view on my django server : 我的django服务器上有以下视图:

@csrf_exempt
def get_post_image(request, postID):
    response_date = {}
    if not request.user.is_authenticated():
        response_date['code'] = 507
        response_date['msg'] = "not logged in"
    else:
        post = Post.objects.get(id=postID)
        image_data = open(settings.MEDIA_ROOT + post.pic.name, "rb").read()
        return HttpResponse(image_data,
                            content_type=mimetypes.guess_type(post.pic.name))

which takes an postID and return its image. 它接受一个postID并返回其图像。 but I want to resize this image (without changing ratio) before send it to client. 但我想在将此图像发送给客户端之前调整其大小(不改变比例)。

How is it possible? 这怎么可能?

for the raw tool for manipulating images from python see: 有关从python处理图像的原始工具,请参见:
https://pillow.readthedocs.org/ https://pillow.readthedocs.org/

...for a Django-integrated image resizing system see: ...有关Django集成的图像大小调整系统,请参阅:
http://easy-thumbnails.readthedocs.org/en/latest/ http://easy-thumbnails.readthedocs.org/en/latest/
or 要么
http://sorl-thumbnail.readthedocs.org/en/latest/ (note the requirements though) http://sorl-thumbnail.readthedocs.org/en/latest/ (请注意要求)

简易缩略图提供了生成缩略图简便方法

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

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