I am trying to change the font size using python's ImageDraw library.
You can do something like this:
fontPath = "/usr/share/fonts/dejavu-lgc/DejaVuLGCSansCondensed-Bold.ttf"
sans16 = ImageFont.truetype ( fontPath, 16 )
im = Image.new ( "RGB", (200,50), "#ddd" )
draw = ImageDraw.Draw ( im )
draw.text ( (10,10), "Run awayyyy!", font=sans16, fill="red" )
The problem is that I don't want to specify a font. I want to use the default font and just change the size of the font. This seems to me that it should be simple, but I can't find documentation on how to do this.
Open the Python shell. Then, in the menu bar, under "Python" (directly to the right of the Apple icon), you will find "Preferences". Under this, you will find the "Font/Tabs" option, and you can change the font size according to your preference.
On the top menu, choose Options , then Configure IDLE . The Fonts/Tabs tab will be displayed. There is a Size button. Click on it and select a bigger size than the default of 10.
Pyscripter Tools menu > Options > Editor Options. Display tab > click Font. Select "Source Code Pro" from list of fonts. Select Style and Size if desired.
Define custom font and color settings for PythonPress Ctrl+Alt+S to open the IDE settings and select Editor | Color Scheme | Python.
Per PIL's docs, ImageDraw
's default font is a bitmap font, and therefore it cannot be scaled. For scaling, you need to select a true-type font. I hope it's not difficult to find a nice truetype font that "looks kinda like" the default font in your desired font-size!
Just do this
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
def image_char(char,image_size, font_size):
img = Image.new("RGB", (image_size, image_size), (255,255,255))
print img.getpixel((0,0))
draw = ImageDraw.Draw(img)
font_path = "/Users/admin/Library/Fonts/InputSans-Regular.ttf"
font = ImageFont.truetype(font_path, font_size)
draw.text((5, 5), char, (0,0,0),font=font)
img.show()
main():
image_char("A",36,16)
if __name__ == '__main__':
sys.exit(main())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With