Adding draw_text enhancements: Alignments and shadows
As I'm doing changes to tailor the library to my needs I'm introducing some changes, and as I love this library I wanted to contribute with some more PRs, so you can choose if you find anyone of them interesting 😉
This pull request introduces a significant enhancement to the text drawing functionality, providing support for precise positioning through alignments and the addition of text shadows. Prior to this change, text positioning was limited to specific coordinates, making it challenging to achieve dynamic layouts.
Changes Made:
-
Alignment Support: Implemented alignment options for text drawing, allowing users to specify coordinates in the form of (x, y) or tuples of alignments like ('center', 'bottom'). Supported a mix of numerical values and alignment strings, such as (0, 'center') to represent a centered position on the y-axis. Introduced the value 'center' to automatically center the text along both the x and y axes. Also added a default changeable 2 pixel padding for the alignments (So top will be 2 pixels separated from y = 0 and left 2 pixels from the x = 0 but won't affect coordinates or center values).
-
Text Shadow Addition Users can now add shadows to text with options for 'horizontal', 'vertical', or 'diagonal' shadow placements. The shadow effect enhances the visibility and aesthetics of the text, providing a more polished appearance.
Additional changes
- Added string docs to draw_text method
Examples
- Drawing text with xy='center' or xy=('center', 'center') value and a vertical black shadow:
- Drawing text with xy=(0, 'bottom') and an horizontal black shadow:
- Drawing text with xy=('right', 40) without any shadow: