Created
January 8, 2016 10:05
-
-
Save mssobhan/b5918669e37f3732e920 to your computer and use it in GitHub Desktop.
This file contains 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 PIL import Image,ImageDraw, ImageFont, ImageEnhance | |
def image_watermark(request,image_id): | |
photo = Photo.objects.get(pk=image_id) | |
basewidth = 640 | |
watermark = Image.open('{0}/{1}'.format(settings.MEDIA_ROOT,'art1.png')) | |
img = Image.open(photo.photo.file) | |
wpercent = (basewidth/float(img.size[0])) | |
hsize = int((float(wpercent)*float(img.size[1]))) | |
img = img.resize((basewidth,hsize),Image.ANTIALIAS) | |
#tmp_file = tempfile.mktemp() | |
img.paste(watermark,(img.size[0]-watermark.size[0],img.size[1]-watermark.size[1]),watermark) | |
#image = img.resize((1400, 560), Image.ANTIALIAS) | |
img.save('{0}/{1}'.format(settings.MEDIA_ROOT,photo.watermarked_image.name), quality=70,opacity=20) #The Quality was 100 | |
#photo.save() | |
wrapper = FileWrapper(open(photo.watermarked_image.url, 'rb')) | |
response = StreamingHttpResponse(wrapper, 'image/jpeg') | |
response['Content-Length'] = os.path.getsize(photo.watermarked_image.url) | |
response['Content-Disposition'] = 'attachment; filename=photo.jpg' | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment