classic_start_slide.py 2.2 KB

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