-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
Add more options to image resizing #2515
Conversation
Actually, for scaling down or up isn't there also the option to center crop? Perhaps the options for each (tag and file) should be:
Some examples of cropping and keeping the aspect ratio with target dimensions of 1000x1000px:
|
Thank you rdswift for the detailed breakdown!
There is not one out of the box when scaling, but there is a separate method to crop, so I can just use that one instead. I should be able to make cropping a separate |
I guess having both the options to scale up and down creates some chances for ambiguity? A bit of an edge case, but for example with these options: If we have a 1000 x 1000 image, should it be scaled down to 800 x 800 or up to 1200 x 1200? For now I gave priority to scaling down. Since rdswift suggested to also add the options to stretch and to square crop, should I add them in this pr? |
Wow, that's a good question. Personally, I think it might depend on the image format option selected. If it's "stretch/shrink", then I think the final size would be 1200x800 (and the image deformed). It it's "crop", then the final size would be 1200x800 (scaled up to 1200x1200 then crop 200px off of the top and bottom). If it's "keep" then the final size would be 800x800 (scaled to make the the largest image that does not exceed either of the target dimensions). Note that in both the "crop" and "keep" options, you really need to compare the horizontal and vertical dimensions of the scaled image (keeping the original image aspect ratio) against the target dimensions to determine how much the source image is scaled. If "crop", then the image is scaled initially so that one target dimension can be exceeded with the other dimension at the target size, and then crop the overflow. If "keep", then the image is scaled such that at least one of the target dimensions is achieved, but neither target dimension is exceeded. The process (which applies to only the "crop" and "keep" options) would be something like:
EDIT: In short, for the 'stretch/shrink' and 'crop' cases, the output image should always match the target dimensions. Of course this also depends on whether the appropriate "scale up" or "scale down" option is enabled. For example, if the scaling factor is > 1 the image should only be scaled up if the "scale up" option is enabled. Similarly, if the scaling factor < 1 the image should only be scaled down if the "scale down" option is enabled. Even if an image is not scaled, cropping may still be applicable if one of the source image dimensions exceeds the corresponding target dimension. |
90ca467
to
c641d3e
Compare
Thank you again rdswift, this was incredibly helpful!
This is exactly what I couldn't understand at first. Now it's like you described.
This makes a lot of sense, but it gets complicated when you have an image with one dimension above the target and the other below, so one scaling factor is above 1 and the other below (like the example above). I added options for cropping and stretching, now the options look like this: I'm still not sure about the names of those radio buttons, or if I should add tooltips. |
Adding a tooltip with a short example might help. |
Not if you follow the process I outlined above to calculate the scaling factor. In that process there is only one scaling factor produced. On another note, if you wanted to simplify things a bit you could leave out the "stretch/shrink" option (even though it's probably the easiest to code). I may be wrong, but I can't see too many people (if any) using that because it intentionally distorts the image. That would leave two scaling options -- "fit" and "fill", defined as:
|
I agree with @zas that tooltips with explanation or example would be beneficial. As for names, perhaps "fit" and "fill" with the tooltips containing the descriptions I provided above? |
Sorry, at first I could not get that to work with the options to either ignore width or height. Now I went back and used your process for when both dimensions are considered. Otherwise, it considers each dimension's scale factor independently. (For stretch it always considers both dimensions independently) Consider that I use the scale factor only for deciding which images should be resized and which should not. For the resizing itself, I use the
These sound perfect, thank you!
Makes sense, I just had to make it rich text, otherwise it wouldn't word wrap for whatever reason. A final question, should I keep or remove the option to stretch images? It doesn't complicate the code by that much. |
Okay, I guess I wasn't paying attention because I missed that the target sizes might only be selected for one dimension. Sorry about that. I'm not sure I understand the reason for this or the use case, but having one of the dimensions optional obviously makes my suggested process for calculating scaling factor inappropriate in that case. On that note, the fill processing option should only be available when both target dimensions are specified. |
Do we really want to have the option to scale up? What is the use case here? |
I have no objection to keeping it, although I expect it won't be used (but I've been wrong many times when I make this kind of assumption). Note that this option should also only be available if the target size is specified in both dimensions. What you may want to consider is to automatically change the scale processing radio button to "fit" if one of the target dimensions is not specified, and disable the scaling entirely if neither target dimension is specified (or disallow both target dimensions from being deselected if scaling is selected). |
I can't think of a case where anyone would want to do that, but too often I've been surprised by what some users request (and expect). 😜 |
Right I'm sorry about that. I removed that and added a line break between the description and the example of each tooltip. I needed to make the tooltip's text rich text somehow, or else it refuses to word wrap and would just look wonky.
For cropping and stretching, if a dimension is disabled, its target value becomes the downloaded image's dimension. So the ignored dimension doesn't change when processed. I understand that it's a combination of options that it's most likely never going to be used, but I'm not sure if it makes sense to outright not allow it?
Someone might want all their cover art images to be a certain size no matter what, even if only smaller images are available for a particular release, at the cost of losing quality. I was asked to add these options to improve on image resizing in #2510, but let me know what needs to be kept or removed, after all you know Picard's users better than I do 😄 |
Ah sorry, I assumed the opposite. Thank you for your patience zas! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Is it the same for the "fit" option, where if a dimension is disabled it will default to the source image dimension in that direction? In that case, an image would never be scaled up, which is not what I would expect. For example, if the source image was 700x700 and only the horizontal target dimension is specified as 1000 (and scaling up was enabled), I would expect the final image to be 1000x1000. If the "crop" and "stretch" options will default a missing target dimension to be the same as the source image dimension in that direction, but in the case of the "fit" option the missing option defaults to an infinitely high number (it is ignored), then our UI is inconsistent and could easily lead to user confusion. In any event, whatever is decided needs to be made very clear to the user, because as it stands the behavior willl either be inconsistent between the processing options or it will be unintuitive. Perhaps there needs to be some text added to the UI, something like: "Note that if a target dimension is not specified for the 'crop' and 'fill' options, it defaults to the source image dimension in that direction, but in the case of the 'fit' option it defaults to an infintely large number." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well and the code looks good.
My only concerns is the complexity, and specifically the UI complexity. I'm not convinced that the "Scale down" and also the "Stretch" option are actually useful. But if someone wants the options in I'll also no argue against.
But I also think my concerns can be addresses in a future iteration with some rework of the UI. Thanks @Aerozol to the suggestions.
Regardless I think we can get this merged now, as this is definitely another step forward. @twodoorcoupe Could you rebase this branch against master? Then the CI runs will also succeed again.
9578048
to
ccf716f
Compare
Yes, this is the case.
I'll try to come up with something that does not complicate the UI even more 😅 Thank you @Aerozol for your valuable suggestions! I definitely like the idea of moving the resize mode selection to a drop down list, and to have a "don't enlarge" check box at the bottom. Like outsidecontext suggested, I will work on these changes in a separate pr. I was thinking it's best to wait until I've added the options to convert image formats, so as to have the whole options page before reworking it.
Ok, thank you! |
Yes, that makes a lot of sense |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
Problem
As suggested by zas, image resizing could do with allowing the user to:
Solution
Here's the new options ui:
![new_options](https://private-user-images.githubusercontent.com/119691774/341170377-da20c68d-f61f-4b4c-83d7-1fb0f74d2ef5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA1MjU3NjYsIm5iZiI6MTcyMDUyNTQ2NiwicGF0aCI6Ii8xMTk2OTE3NzQvMzQxMTcwMzc3LWRhMjBjNjhkLWY2MWYtNGI0Yy04M2Q3LTFmYjBmNzRkMmVmNS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzA5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcwOVQxMTQ0MjZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02MDU1NDEzZDYwMWY2NWI5YWE2YjJmZjAxMjE2YmRmZGU5MzE1NWNiMmIzZTVmMDIxMmRjY2VmZjJjN2Q5YWJhJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.I22cDUlnbntaweKR0h3MVSPxdlKtsNdizzAv3DSbyjE)
Unfortunately, I think this complicates the code quite a bit, due to all the different combinations of options. So I'm still trying to figure out if it can be improved on that front.
Also, I'm still working on creating the unit tests for each of those combinations.
Another doubt I have: for scaling up, I assumed the image should keep the aspect ratio with respect to the largest target dimension. As opposed to scaling down, for which we keep the aspect ratio with respect to the smallest target dimension.
Action
Additional actions required: