Skip to content
Branch: master
Find file Copy path
Find file Copy path
2 contributors

Users who have contributed to this file

@aknuds1 @chief-wizard
executable file 59 lines (47 sloc) 1.33 KB
import datetime
import json
import os
from io import BytesIO
import boto3
import PIL
from PIL import Image
def resized_image_url(resized_key, bucket, region):
return "https://s3-{region}{bucket}/{resized_key}".format(
bucket=bucket, region=region, resized_key=resized_key
def resize_image(bucket_name, key, size):
size_split = size.split('x')
s3 = boto3.resource('s3')
obj = s3.Object(
obj_body = obj.get()['Body'].read()
img =
img = img.resize(
(int(size_split[0]), int(size_split[1])), PIL.Image.ANTIALIAS
buffer = BytesIO(), 'JPEG')
resized_key="{size}_{key}".format(size=size, key=key)
obj = s3.Object(
obj.put(Body=buffer, ContentType='image/jpeg')
return resized_image_url(
resized_key, bucket_name, os.environ["AWS_REGION"]
def call(event, context):
key = event["pathParameters"]["image"]
size = event["pathParameters"]["size"]
result_url = resize_image(os.environ["BUCKET"], key, size)
response = {
"statusCode": 301,
"body": "",
"headers": {
"location": result_url
return response
You can’t perform that action at this time.