Skip to content

Commit

Permalink
add flip image horizontally button
Browse files Browse the repository at this point in the history
  • Loading branch information
hananbeer committed Mar 9, 2023
1 parent d8a7c50 commit f85a4c9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions javascript/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ function extract_image_from_gallery(gallery){
return [gallery[index]];
}

function flip_images(gallery_name) {
let imgs = gradioApp().getElementById(`${gallery_name}_gallery`).querySelectorAll('img')
for (let i = 0; i < imgs.length; i++) {
imgs[i].classList.toggle('flipped_h')
}
}


function flip_gallery_images() {
flip_images('txt2img')
flip_images('img2img')
}

function args_to_array(args){
res = []
for(var i=0;i<args.length;i++){
Expand Down
6 changes: 6 additions & 0 deletions modules/ui_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def open_folder(f):
if tabname != "extras":
save = gr.Button('Save', elem_id=f'save_{tabname}')
save_zip = gr.Button('Zip', elem_id=f'save_zip_{tabname}')
flip_img = gr.Button('Flip', elem_id=f'flip_img_{tabname}')

buttons = parameters_copypaste.create_buttons(["img2img", "inpaint", "extras"])

Expand Down Expand Up @@ -193,6 +194,11 @@ def open_folder(f):
]
)

flip_img.click(
fn=lambda x: None,
_js="(x) => { flip_gallery_images(); return 1; }"
)

else:
html_info_x = gr.HTML(elem_id=f'html_info_x_{tabname}')
html_info = gr.HTML(elem_id=f'html_info_{tabname}')
Expand Down
4 changes: 4 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -959,3 +959,7 @@ footer {
[id*='_prompt_container'] > div {
margin: 0!important;
}

.flipped_h {
transform: scaleX(-1)
}

1 comment on commit f85a4c9

@hananbeer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flip image horizontally button.
feature requested in #8419

Please sign in to comment.