Reputation: 1594
I have the following view on my django server :
@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. but I want to resize this image (without changing ratio) before send it to client.
How is it possible?
Upvotes: 0
Views: 385
Reputation: 33833
for the raw tool for manipulating images from python see:
https://pillow.readthedocs.org/
...for a Django-integrated image resizing system see:
http://easy-thumbnails.readthedocs.org/en/latest/
or
http://sorl-thumbnail.readthedocs.org/en/latest/ (note the requirements though)
Upvotes: 1
Reputation: 45575
Easy-thumbnails provides the easy way of generating thumbnails.
Upvotes: 1