Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve autoscaling behavior #395

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

askmeaboutlo0m
Copy link
Contributor

A few things in here, check the individual commits for more details. The main issue here is that when you post to Bsky, the image gets scaled to a dinky 1000x1000 size, which is a) wrong, because it exceeds the maximum scale amount I set and b) bad, because it could just use a pretty good quality JPEG instead and not lose any size.

So this PR does a few things in that regard.

It takes the maximum scale amount set by the user relative to the original image size, not the size after rescaling the image according to website limits. Presumably this was the intended behavior to begin with, so this is just a bugfix.

Maybe somewhat controversially, it now prefers quality reduction over size reduction by default, at least for images that don't have an alpha channel. Reducing JPEG quality is notably faster than trying a bunch of resizing and, in my opinion, gives better visual quality than having a smaller image. It's a preference, so users that don't want this can still disable it.

It corrects the maximum image size in bytes for Bsky. It was set to 0.9 MiB, but it's really 1000000 bytes. Only a difference of 55 KiB, but hey.

Finally, it marks Bsky as not supporting alpha. If a website sets this flag, the file munger will act accordingly resizing the image as if it didn't have alpha and converting to JPEG more eagerly.

I'll be marking this as tentative, since it could use some feedback and testing first.

Not relative to the image size after resizing it to fit the website
limits, otherwise we potentially end up scaling them way smaller than
the user preference specified.
By introducing a setting to that effect, disabled by default, and
preferring to reduce quality instead by default. Reducing JPEG quality
is a much faster operation and retains visual quality pretty well, as
opposed to scaling an image to some kind of dinky size, so I think it
makes sense to enable this by default. Images with alpha transparency
will continue to prefer being scaled smaller before punting to JPEG to
avoid losing the alpha channel.
It's 1000000 bytes, not 0.9 MiB.
Because the website itself doesn't support alpha transparency. We now
always act as if images provided to it don't have alpha, meaning we use
the non-alpha resize setting and punt to JPEG immediately if quality
reduction is preferred.
@askmeaboutlo0m askmeaboutlo0m marked this pull request as draft December 18, 2024 05:13
@leaftail1880
Copy link
Contributor

Was also about to work on this, glad you did it. I will test it by myself soon and provide devbuild for friends to test.

@askmeaboutlo0m
Copy link
Contributor Author

I tested it meanwhile, worked for me and resized the images nicely. So I'm happy with how it's working currently, but I'll wait for further comments.

@leaftail1880
Copy link
Contributor

Okay, so far i encoutered these errors:

Im using this image set for testing

IMG F 1
Failed IMG 1

IMG S 1
Succesful IMG 1

IMG S 2
Succesful IMG 2

IMG S 3
Successful IMG 3

This set of images was provided by FatBluDragon from Discord

Behavior Old New New + Enabled Reduce Size Before Quality
IMG F 1 (469 КБ, 4961x3508) ❌ This file is too large. It is 4.76MB but the maximum size is 976.56KB ❌ This file is too large. It is 2.62MB but the maximum size is 976.56KB.
IMG S 1 (951 КБ, 1800x3508) ❌ This file is too large. It is 2.62MB but the maximum size is 976.56KB. ❌ This file is too large. It is 2.62MB but the maximum size is 976.56KB.
IMG S 2 (993 КБ, 4961x1572) ❌ Unable to successfully scale image down to 1000000 bytes from 1017014 bytes
IMG S 3 (927 КБ, 4961x3508) ❌ This file is too large. It is 4.55MB but the maximum size is 976.56KB. ❌ This file is too large. It is 4.55MB but the maximum size is 976.56KB.

Please note that all other image scaling settings are set to defaults

To be able to tell why the heck it's producing images that are larger
than the input image.
It was checking the input file size, not the resized image size.
However, resizing the image smaller can actually *increase* the size.
Now it properly checks the buffer it's actually going to be posting.

This should fix mvdicarlo#328.
@askmeaboutlo0m
Copy link
Contributor Author

Fixed the (pre-existing) bug that images get rescaled to a larger size and posted all of the given images without error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants