feat: Use resize when resampling images with up to 2.56 megapixels#8001
Draft
72374 wants to merge 5 commits intochatmail:mainfrom
Draft
feat: Use resize when resampling images with up to 2.56 megapixels#800172374 wants to merge 5 commits intochatmail:mainfrom
resize when resampling images with up to 2.56 megapixels#800172374 wants to merge 5 commits intochatmail:mainfrom
Conversation
to the only part of the function where it is used.
Currently, the resolution of a resized image that was sent in a chat, depends on the aspect-ratio. Assuming the `balanced`-quality-setting is used, a square image, that is larger than the limits for resolution and file-size, will be resized to 1280x1280 (1,638,400 pixels), an image with an aspect-ratio of 16:9, will be resized to 1280x720 (921,600 pixels), and if the aspect-ratio is 32:9, to 1280x360 (460,800 pixels). This change makes it so, that the number of pixels, in images with different aspect-ratios, will be similar.
The file-size of many images will already be smaller than 20 kB, when encoded at 256x256, and it can be a large improvement in quality.
The resolution-limits for avatar-images are currently 512x512 or 256x256. Reducing the resolution further, to 2/3 each step, can reduce the quality much more than is necessary to fit within the file-size-limits, which are currently 60 kB or 20 kB. An image made entirely of noise (which results in unusually large file-sizes), encoded with jpeg-quality 75, and 4:2:2-colour-subsampling (the format currently used for encoding images), can be below 60 kB at 227x227. For the lower file-size-limit of 20 kB, such images can be too large at 170x170, but fit at 149x149. More normal images will have a lower file-size at the same resolution. Before this change, the target-resolutions for resampling were: 512x512 -> 341x341 -> 227x227. And for the lower file-size-limit: 256x256 -> 170x170 -> 113x113. After this change, the target-resolutions for resampling will be: 512x512 -> 448x448 -> 392x392 -> 343x343 -> 300x300 -> 262x262 -> 229x229. And for the lower file-size-limit, those will be: 256x256 -> 224x224 -> 196x196 -> 171x171 -> 149x149 -> 130x130 -> 113x113. This does add 2 steps between the previous target-resolutions, while still reaching target-resolutions close to the previous ones, to reduce situations in which the quality will be lower than before.
dca6ba7 to
d8397bc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
thumbnail-function can resample images quickly, but with very noticeable aliasing when it is used to resample images to a close resolution (~80% of the original resolution, for example). Even if the resolution-difference is large, the quality of the resampling is rather flawed. The function is for quickly resampling lots of images into tiny preview-images, for which the quality is not particularly important, and the resolution-difference is usually large (~20% of the original resolution, for example).The amount of processing (and thus time) required to resample images, depends on the resolution of the original image.
By using the
thumbnail-function only for images with a high resolution, many images will be resampled with the better resampling of theresize-function, while the processing-time, when resampling images with a high resolution, will still be relatively short.Based on #7822 . The latest commit in this PR is the relevant commit for this PR.