Twitter for some reson refuses to serve some image files (deleted tweet?)
This commit is contained in:
parent
9771d3fed8
commit
b19f552e70
BIN
combineImg/500.jpg
Normal file
BIN
combineImg/500.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 57 KiB |
@ -26,9 +26,9 @@ RUN yum -y install tar gzip zlib freetype-devel \
|
||||
RUN pip install -U --force-reinstall pillow-simd
|
||||
RUN pip install requests
|
||||
|
||||
|
||||
# Copy function code
|
||||
COPY __init__.py ${LAMBDA_TASK_ROOT}/app.py
|
||||
COPY 500.jpg ${LAMBDA_TASK_ROOT}/500.jpg
|
||||
|
||||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
|
||||
CMD [ "app.lambda_handler" ]
|
@ -93,6 +93,10 @@ def combineImages(imageArray, totalWidth, totalHeight,pad=True):
|
||||
def saveImage(image, name):
|
||||
image.save(name)
|
||||
|
||||
def get500ImgBase64():
|
||||
data = open("500.jpg","rb").read()
|
||||
return (base64.b64encode(data)).decode('ascii')
|
||||
|
||||
# combine up to four images into a single image
|
||||
def genImage(imageArray):
|
||||
totalSize=getTotalImgSize(imageArray)
|
||||
@ -140,7 +144,7 @@ def lambda_handler(event, context):
|
||||
return {'statusCode':400,'body':'Invalid image URL'}
|
||||
combined = genImageFromURL(images)
|
||||
if (combined == None):
|
||||
return {'statusCode':500,'body':'Failed to download image(s)'}
|
||||
return {'statusCode':200,'body':get500ImgBase64(),'isBase64Encoded':True,'headers':{"Content-Type": "image/jpeg","Cache-Control": "public, max-age=86400"}}
|
||||
buffered = BytesIO()
|
||||
combined.save(buffered,format="JPEG",quality=60)
|
||||
combined_str=base64.b64encode(buffered.getvalue()).decode('ascii')
|
||||
|
Loading…
x
Reference in New Issue
Block a user