postprocessing_create_flipped_copies.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. from PIL import ImageOps, Image
  2. from modules import scripts_postprocessing, ui_components
  3. import gradio as gr
  4. class ScriptPostprocessingCreateFlippedCopies(scripts_postprocessing.ScriptPostprocessing):
  5. name = "Create flipped copies"
  6. order = 4000
  7. def ui(self):
  8. with ui_components.InputAccordion(False, label="Create flipped copies") as enable:
  9. with gr.Row():
  10. option = gr.CheckboxGroup(value=["Horizontal"], choices=["Horizontal", "Vertical", "Both"], show_label=False)
  11. return {
  12. "enable": enable,
  13. "option": option,
  14. }
  15. def process(self, pp: scripts_postprocessing.PostprocessedImage, enable, option):
  16. if not enable:
  17. return
  18. if "Horizontal" in option:
  19. pp.extra_images.append(ImageOps.mirror(pp.image))
  20. if "Vertical" in option:
  21. pp.extra_images.append(pp.image.transpose(Image.Transpose.FLIP_TOP_BOTTOM))
  22. if "Both" in option:
  23. pp.extra_images.append(pp.image.transpose(Image.Transpose.FLIP_TOP_BOTTOM).transpose(Image.Transpose.FLIP_LEFT_RIGHT))