Skip to content

Commit b19f552

Browse files
committed
Twitter for some reson refuses to serve some image files (deleted tweet?)
1 parent 9771d3f commit b19f552

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

combineImg/500.jpg

57 KB
Loading

combineImg/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ RUN yum -y install tar gzip zlib freetype-devel \
2626
RUN pip install -U --force-reinstall pillow-simd
2727
RUN pip install requests
2828

29-
3029
# Copy function code
3130
COPY __init__.py ${LAMBDA_TASK_ROOT}/app.py
31+
COPY 500.jpg ${LAMBDA_TASK_ROOT}/500.jpg
3232

3333
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
3434
CMD [ "app.lambda_handler" ]

combineImg/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def combineImages(imageArray, totalWidth, totalHeight,pad=True):
9393
def saveImage(image, name):
9494
image.save(name)
9595

96+
def get500ImgBase64():
97+
data = open("500.jpg","rb").read()
98+
return (base64.b64encode(data)).decode('ascii')
99+
96100
# combine up to four images into a single image
97101
def genImage(imageArray):
98102
totalSize=getTotalImgSize(imageArray)
@@ -140,7 +144,7 @@ def lambda_handler(event, context):
140144
return {'statusCode':400,'body':'Invalid image URL'}
141145
combined = genImageFromURL(images)
142146
if (combined == None):
143-
return {'statusCode':500,'body':'Failed to download image(s)'}
147+
return {'statusCode':200,'body':get500ImgBase64(),'isBase64Encoded':True,'headers':{"Content-Type": "image/jpeg","Cache-Control": "public, max-age=86400"}}
144148
buffered = BytesIO()
145149
combined.save(buffered,format="JPEG",quality=60)
146150
combined_str=base64.b64encode(buffered.getvalue()).decode('ascii')

0 commit comments

Comments
 (0)