0

I'm new to Python and programing in gneral. I'm a self-learner and I decided that I would write a command line tool that would help me make watchfaces for Mi Band 4. So I want to generate; numbers, days of weeks and some specials characters in different fonts and sizes, and that's my problem, I don't want to manually type in width and height for every image and font, because then there woudln't be any point in making it. I want the tool to dynamically adjust the width and height by itself depending on the font size.

I'm on python 3.7.4 and I was working with "pillow" before. Thanks for any help

Daburu
  • 109
  • 1
  • 11
  • What exactly is your question? It is trivial to get the size of an image in pillow – mousetail Nov 19 '19 at 14:27
  • @mousetail I want the tool to generate a image with text e.x. "Mon" with font size 12 which results in text that's 16px high and 32px wide, I want the backgound image to be the same height and width so 16x32px but I don't know how to get the height of the font in px, if there was something like background-color in css it would be a lot easier – Daburu Nov 19 '19 at 14:46
  • You can use `PIL.ImageFont.ImageFont.getsize(text)` (https://pillow.readthedocs.io/en/3.1.x/reference/ImageFont.html) – mousetail Nov 20 '19 at 13:40
  • @mousetail thanks, I also found imageDraw.textsize, which should return the size in px, I'm going to try your solution if it doesn't work – Daburu Nov 20 '19 at 13:52
  • This is similar... https://stackoverflow.com/a/33875472/2836621 – Mark Setchell Dec 03 '19 at 15:25

0 Answers0