Use image.thumbnail
This commit is contained in:
parent
104212529f
commit
0abff499e2
2 changed files with 2 additions and 18 deletions
|
@ -89,15 +89,7 @@ def get_SD_pictures(description):
|
||||||
image.save(output_file.as_posix())
|
image.save(output_file.as_posix())
|
||||||
pic_id += 1
|
pic_id += 1
|
||||||
# lower the resolution of received images for the chat, otherwise the log size gets out of control quickly with all the base64 values in visible history
|
# lower the resolution of received images for the chat, otherwise the log size gets out of control quickly with all the base64 values in visible history
|
||||||
width, height = image.size
|
image.thumbnail((300, 300))
|
||||||
if (width > 300):
|
|
||||||
height = int(height * (300 / width))
|
|
||||||
width = 300
|
|
||||||
elif (height > 300):
|
|
||||||
width = int(width * (300 / height))
|
|
||||||
height = 300
|
|
||||||
newsize = (width, height)
|
|
||||||
image = image.resize(newsize, Image.LANCZOS)
|
|
||||||
buffered = io.BytesIO()
|
buffered = io.BytesIO()
|
||||||
image.save(buffered, format="JPEG")
|
image.save(buffered, format="JPEG")
|
||||||
buffered.seek(0)
|
buffered.seek(0)
|
||||||
|
|
|
@ -26,15 +26,7 @@ def caption_image(raw_image):
|
||||||
def generate_chat_picture(picture, name1, name2):
|
def generate_chat_picture(picture, name1, name2):
|
||||||
text = f'*{name1} sends {name2} a picture that contains the following: "{caption_image(picture)}"*'
|
text = f'*{name1} sends {name2} a picture that contains the following: "{caption_image(picture)}"*'
|
||||||
# lower the resolution of sent images for the chat, otherwise the log size gets out of control quickly with all the base64 values in visible history
|
# lower the resolution of sent images for the chat, otherwise the log size gets out of control quickly with all the base64 values in visible history
|
||||||
width, height = picture.size
|
image.thumbnail((300, 300))
|
||||||
if (width > 300):
|
|
||||||
height = int(height * (300 / width))
|
|
||||||
width = 300
|
|
||||||
elif (height > 300):
|
|
||||||
width = int(width * (300 / height))
|
|
||||||
height = 300
|
|
||||||
newsize = (width, height)
|
|
||||||
picture = picture.resize(newsize, Image.LANCZOS)
|
|
||||||
buffer = BytesIO()
|
buffer = BytesIO()
|
||||||
picture.save(buffer, format="JPEG")
|
picture.save(buffer, format="JPEG")
|
||||||
img_str = base64.b64encode(buffer.getvalue()).decode('utf-8')
|
img_str = base64.b64encode(buffer.getvalue()).decode('utf-8')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue