classic_start_slide.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """
  2. Copyright © 2022 Noah Vogt <noah@noahvogt.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. """
  14. from wand.image import Image
  15. from wand.color import Color
  16. from wand.font import Font
  17. from .start_slide import StartSlide
  18. try:
  19. import config.config as const # pyright: ignore [reportMissingImports]
  20. except ModuleNotFoundError:
  21. import config.default_config as const
  22. class ClassicStartSlide(StartSlide):
  23. def get_slide(
  24. self,
  25. template_img: Image,
  26. book: str,
  27. text_author: str,
  28. melody_author: str,
  29. ) -> Image:
  30. start_img = template_img.clone()
  31. start_img.composite(
  32. self.get_attributions(text_author, melody_author),
  33. left=const.METADATA_X,
  34. top=const.ATTRIBUTIONS_Y,
  35. )
  36. start_img.composite(
  37. self.get_book(book), left=const.METADATA_X, top=const.BOOK_Y
  38. )
  39. return start_img.clone()
  40. def get_metadata(self, text: str) -> Image:
  41. with Image(
  42. width=const.WIDTH,
  43. height=const.HEIGHT,
  44. background=Color(const.BG_COLOR),
  45. ) as img:
  46. img.caption(
  47. text,
  48. font=Font(
  49. const.FONT_PATH,
  50. size=const.METADATA_FONT_SIZE,
  51. color=Color(const.TEXT_COLOR),
  52. ),
  53. )
  54. img.trim()
  55. return img.clone()
  56. def get_attributions(self, text_author: str, melody_author: str) -> Image:
  57. if text_author == melody_author:
  58. return self.get_metadata("Text & Melodie: " + text_author)
  59. return self.get_metadata(
  60. "Text: " + text_author + "\nMelodie: " + melody_author
  61. )
  62. def get_book(self, book: str) -> Image:
  63. return self.get_metadata(book)