Last active
August 29, 2015 14:11
-
-
Save Snakeyyy/ae4a164401e36c5b4886 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sorl.thumbnail import get_thumbnail | |
from django.http import HttpResponseRedirect | |
def responsive_image(request): | |
image_path = request.GET.get('image_path') | |
width = int(request.GET.get('width')) | |
height = int(request.GET.get('height')) | |
is_retina = bool(request.GET.get('is_retina', False)) | |
if is_retina: | |
width *= 2 | |
height *= 2 | |
if not image_path or not width or not height: | |
return HttpResponse(content='missing get parameters', status=404) | |
path_ = 'http://'+request.META['HTTP_HOST'] + image_path | |
thumb = get_thumbnail(path_, '%dx%d' % (width, height)) | |
return HttpResponseRedirect(thumb.url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment