Commit a17a4361 authored by Dan Pascu's avatar Dan Pascu

Optimized chat inline images to avoid compression artifacts

parent 1255e956
......@@ -500,12 +500,14 @@ class Thumbnail(object):
image_format = str(image_reader.format())
image_data = str(image_reader.device().readAll())
else:
file_format = str(image_reader.format())
file_size = image_reader.device().size()
image_size = image_reader.size()
if image_size.height() > 720:
image_reader.setScaledSize(image_size * 720 / image_size.height())
image = QPixmap.fromImageReader(image_reader)
image_buffer = QBuffer()
image_format = 'png' if image.hasAlphaChannel() else 'jpeg'
image_format = 'png' if image.hasAlphaChannel() or (file_format in {'png', 'tiff', 'ico'} and file_size <= 100*1024) else 'jpeg'
image.save(image_buffer, image_format)
image_data = str(image_buffer.data())
instance = super(Thumbnail, cls).__new__(cls)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment