classic_start_slide.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. import config as const
  18. from .start_slide import StartSlide
  19. class ClassicStartSlide(StartSlide):
  20. def get_slide(
  21. self,
  22. template_img: Image,
  23. book: str,
  24. text_author: str,
  25. melody_author: str,
  26. ) -> Image:
  27. start_img = template_img.clone()
  28. start_img.composite(
  29. self.get_attributions(text_author, melody_author),
  30. left=const.METADATA_X,
  31. top=const.ATTRIBUTIONS_Y,
  32. )
  33. start_img.composite(
  34. self.get_book(book), left=const.METADATA_X, top=const.BOOK_Y
  35. )
  36. return start_img.clone()
  37. def get_metadata(self, text: str) -> Image:
  38. with Image(
  39. width=const.WIDTH,
  40. height=const.HEIGHT,
  41. background=Color(const.BG_COLOR),
  42. ) as img:
  43. img.caption(
  44. text,
  45. font=Font(
  46. const.FONT_PATH,
  47. size=const.METADATA_FONT_SIZE,
  48. color=Color(const.TEXT_COLOR),
  49. ),
  50. )
  51. img.trim()
  52. return img.clone()
  53. def get_attributions(self, text_author: str, melody_author: str) -> Image:
  54. if text_author == melody_author:
  55. return self.get_metadata("Text & Melodie: " + text_author)
  56. return self.get_metadata(
  57. "Text: " + text_author + "\nMelodie: " + melody_author
  58. )
  59. def get_book(self, book: str) -> Image:
  60. return self.get_metadata(book)