-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
Aspect ratio sliders #7601
Aspect ratio sliders #7601
Conversation
Default choices added to settings in user interface section Choices are editable by user User selects from dropdown. When you move one slider, the other adjusts according to the ratio chosen. Vice versa for the other slider. Number fields for changes work as well. For disabling ratio, an unlock pad "🔓" is available as a default. This string can be changed to anything to serve as a disable, as long as there is no colon ":". Ratios are entered in this format, floats or ints with a colon "1:1". The string is split at the colon, parses left and right as floats to perform the math.
wow that very clean, nice work! issueresolution need to be in steps of 8 currently you're using personally I rather have 16:9.05 then 16:8.95 |
I'm not sure how I would work the math for different ratios. I forget how to do math, the computer does it. I feel like this is grade school math, something like greatest common denominator. 😆 Oh man. |
lol
yes it is 😆 function roundStepUp(number, step) {
return Math.ceil(number / step ) * step;
}
console.log(roundStepUp(64, 8)) // 64
console.log(roundStepUp(64.1, 8)) // 72
console.log(roundStepUp(72, 8)) // 72
console.log(roundStepUp(127, 8)) // 128
console.log(roundStepUp(128, 8)) // 128
console.log(roundStepUp(129, 8)) // 136 forgot to mention there is no need to round down the number to an integer |
I'm ready. Seems to be working. Have not tested it with a cinematic ratio. I forgot to remove the other 'rounds' that should not be needed. |
@w-e-w Thanks for helping and holding me accountable. This is turning out alright. |
no not working |
wait a moment |
Huh. It's acting like I didn't trigger the change event when I change the dropdown. |
I made a change on the slider component controller. I noticed it wasn't updating the backend in all scenarios, just some. I'm going to explore my logic. I might've missed something small. |
Cool I like it |
I noticed, when I use the up/down arrow in the number field, 16:9, it can change from 712 to 784 on width, while height stays at 424. |
Could you take a look at this? It uses step of 64 instead of 8 |
this thing looks quite old see webui did use step 64 couple months ago however if you are old user of webui backthen |
https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/processing.py#L35 sorry that I can only give suggestions and help debug |
I think I understand the issue, there was a conflict, and my stuff was off. I removed the conflict. I have it in my head on how to fix it, but have to spell it out. |
just in case there's any misunderstanding |
@w-e-w The same with 528x297. I think it's ready for another round of checks, I tested it with 1.85:1, but I can't do high numbers (I temporary changed the max on the sliders, they work as long as you have enough memory, tested with 64x2496 to see if I can go above 2048, and yes). |
good newsdid some quick test and didn't find any issues bad newsI don't think enforcing that the aspect ratio is perfect is a good idea first issue this makes this ratio slider FAR less usefulin an applications such as Photoshop or Gimp
and in my opinion I would prefer the ratio to be round UP rather than down, but instead if I round down the image will be 600x1064, I will need to crop theis image to 599x1064 then scale it up by a small amount
the second issue of enforcing the perfect aspect ratiofor example 1:1.3 the solutionyou simply need to round up the other number to the nearest multiple of 8function roundStepUp(number, step) {
return Math.ceil(number / step ) * step;
} however someone do prefer rounding down, you simply have to change maybe someone do wish exact ratio (though I don't see it), I think you can keep this under an option just let the user deal which non exact aspect ratio, the same way that it has been done in graphic softwares |
I don't think I'm going to round it off. Some will expect pixel perfect and some wont care. It does have the ability to put in a different ratio. So if it needs to be slightly off, it can be done there to change the scaling. |
1:1.3 is so close to 1:1, why not use 1:1, go next step up and trim 6 pixels off one edge. |
I get it. I'm going to poke around a little and think about it. |
b030b67
to
374fe63
Compare
@AUTOMATIC1111 we made aspect ratio slider using a different approach from previous rejected PRs
by default it is not active and does not interfere with normal use the list of aspect ratio can be manually configured in the settings I hope this PR will get merged here is a short example of the implementation in action old video new updated below2023-02-09.23-30-06.Replay.mp4 |
2023-02-10.09-07-09.Replay.mp4 |
remove Badge background and⚠️ ->📏
I hated the symbol. I was using a round badge to indicate rounding, and a square badge to indicate ?sharper?, but it seemed to have issues depending on font size and character. |
there seems to be something wrong with to github workflow testother people's tests have also failed
LOL, so that was what you were thinking, before looking at the code I thought it was some sort of drawing issue there are tons of good emojis to choose from emojis⬆️ Up Arrow I gess if we really want to we can make the symbol customizable |
@Gerschel you might want to update that, so AUTO doesn't get confused, no telling when he will be back |
I updated it and moved it to the head of this request. That way there is no having to dig and jump around. I imagine Automatic1111 is doing a ui overhaul, code clean-up/restructure and some documentation. So he can do a proper release version and hopefully set some standards. |
I pressed merge by accident. It's marked as merged but I reverted it. There is way too much javascript for me in this. Merging this in means that I will also have to maintain it. The preferred way for those things is for them to be an extension. If something needs to be added into the main repo for the extension to work, that can be added in. The js library will not be added. Additionally, this produces errors in the JS console of the browser; additionally, I have step of 64 for width/height sliders, and changing the aspect ratio option once undoes the 64 piel step until page reload. |
@AUTOMATIC1111 the width/height step has been set to 8 since PR #4978 it's been like this for months and I don't see people having issues |
My preference is having step of 64. I specifically set it to 64 for myself. |
I see I guess we can try and make it an extension then need to look into it |
The |
I will try to come up with a way where it uses more of the backend (python). The first attempt did that, but had the annoying white flash on the components. After playing with a few other things, I believe that flash is becasue there is a moment where the dark mode css does not apply, which I believe is caused by lag by too many calls because of event type. I'm aware of the potential need for setting the target (gradio-app/gradio#2981 (comment)), I thought my console errors were because of my symlinks getting broken with other projects. So I'll double check it. Thanks for informing me of seeing them on your end as well. With the current structure, it is possible to swap the step size rounding to other numbers, but to make it clean, it should be set as a class variable and allow the value to be set by the user. If anyone knows where I can find the user's default value (8 or 64), that would be helpful, but I'll probably find it, so I can set a default. The hardest part of converting from javascript to python would be the clickable badge. So I will need to think about this for a moment. I'm going to do a work sprint starting today until March 5th (home and garden show, emerald city comiccon build/dismantle and some other show in oregon), I wont have much time between now and then. |
I might give it a go to, (mostly an excuse for me to learn some javascript) |
If you're trying to make it like an extension, use css to target the name in the dropdown and hide it, because it technically does not have a "run" method. There are two ScriptRunner instances in the webui, one is txt2img and the other is img2img, each of these instances will call the "show" method, to determine if they will show on it's page. This means there are two instances of your python class. Javascript can be used to grab the dropdown and move it to the desired location. Instead of That can leave ui.py untouched, but is more overhead in javascript, as you'll need to grab the toolbox created by the python script, insert the swap button into the toolbox, then insert the toolbox after the width/height column. Pretty much, all the python code that currently exists for this can be put into a python class. Target it with js. let toolbox = gradioApp().getElementById("txt2img_size_toolbox")
toolbox.appendChild("txt2img_res_switch_btn");
gradioApp().getElementById("txt2img_column_size").insertAdjacent("afterend", toolbox) If trying to do it as a built-in, javascript maths can be moved to python, either use existing js functions provided by the webui, or embed a minimal amount in the python components |
thanks for the advice I'm preparing myself to fail spectacularly |
@w-e-w any update on a potential extension. For anyone looking for something basic I found https://github.com/alemelis/sd-webui-ar |
@SeanBannister essentially he doesn't want too much JavaScript in the main webui, because if so he would have to support it in the future he said that we could make it a plug-in and if anything that "needs" to be added into the main repo it can as for progress |
I created this extension for my own usage in-case anyone is interested: https://github.com/thomasasfk/sd-webui-aspect-ratio-helper |
https://github.com/AUTOMATIC1111/stable-diffusion-webui-extensions |
Sliders adjust according to aspect ratio.
Default choices added to settings in user interface section
Choices are editable by user
User selects from dropdown.
When you move one slider, the other adjusts according to the ratio chosen.
Vice versa for the other slider.
Number fields for changes work as well.
For disabling ratio, an unlock pad "🔓" is available as a default.
This string can be changed to anything to serve as a disable,
as long as there is no colon ":" in the string.
Ratios are entered in this format, floats or ints with a colon "1:1".
The string is split at the colon, parses left and right as floats to
perform the math.
More technical discussion about your changes go here, plus anything that a maintainer might have to specifically take a look at, or be wary of.
I included the componentController library, as this uses it.
Environment this was tested in
Now for the demos:
Video demonstration:
https://user-images.githubusercontent.com/40751091/217967464-d9d9cb67-a195-4697-b11f-137d14cf42af.mp4
On settings tab:
On txt2img and img2img, it is a dropdown that looks like a button, it has an indicator that can hot swap the setting:
In the upper right corner is the indicator, it's clickable, this indicates it's in precision mode:
This indicates it's in rounding mode:
.
Changing round/precision mode literally changes and reads from the setting, making it hot swappable, no save and apply necessary unless you want to tell the app which value to use as default on start-up.
.
.
The reason it has two modes, models have a limitation of step 8. To keep a ratio intact and on a multiple of 8, we end up skipping 7 valid ratio coordinates for every perfect match. This is why there is rounding mode, so you can get close, and it rounds to a nearby step 8, which throws off the aspect ratio a little, but keeps you from having to do ratio math for every image, and keeps you from generating unnecessary stuff you'll crop out.
Rounding mode gives users options, some will want to round up, round nearest, or round down. This is to give them flexibility and makes it easier for users to know what behavior to expect when adjusting sliders.
.
.
The dropdown has choices of aspect ratios, these are configurable in settings:
When a ratio is selected in the dropdown/button, the sliders will initially snap to complimentary values, how accurate depends on your settings.
Then using either the sliders or number fields, the values will move accordingly (by precision/rounding and by ratio).
When you don't want them to have a ratio, there is an unlocked pad as a symbol, which is on by default. When the sliders are unlocked, it hides the indicator. This symbol can be changed in the settings as well.
The javascript class is setup to be reusable, just reference your element id's and call its static method for it to start it's own observer.
You will need to have two sliders, a dropdown that has your ratios, a checkbox for a rounding source and a radio for rounding method. This will allow others to implement it in their scripts/extensions.