Python Imaging Library(ImageFont Module)














































Python Imaging Library(ImageFont Module)



ImageFont Module The ImageFont module defines a class with the same name. Instances of this class store bitmap fonts, and are used with the PIL.ImageDraw.Draw.text() method. PIL uses its own font file format to store bitmap fonts. You can use the pilfont utility to convert BDF and PCF font descriptors (X window font formats) to this format. Starting with version 1.1.4, PIL can be configured to support TrueType and OpenType fonts (as well as other font formats supported by the FreeType library). For earlier versions, TrueType support is only available as part of the imToolkit package Example from PIL import ImageFont, ImageDraw draw = ImageDraw.Draw(image) # use a bitmap font font = ImageFont.load("arial.pil") draw.text((10, 10), "hello", font=font) # use a truetype font font = ImageFont.truetype("arial.ttf", 15) draw.text((10, 25), "world", font=font) Functions 1.PIL.ImageFont.load(filename) Load a font file. This function loads a font object from the given bitmap font file, and returns the corresponding font object. Parameters: filename -: Name of font file. Returns:A font object. Raises: IOError - If the file could not be read. 2.PIL.ImageFont.load_path(filename) Load font file. Same as load(), but searches for a bitmap font along the Python path. Parameters: filename -: Name of font file. Returns:A font object. Raises: IOError - If the file could not be read. 3.PIL.ImageFont.truetype(font=None, size=10, index=0, encoding='', layout_engine=None) Load a TrueType or OpenType font from a file or file-like object, and create a font object. This function loads a font object from the given file or file-like object, and creates a font object for a font of the given size. This function requires the _imagingft service. Parameters: font -: A filename or file-like object containing a TrueType font. Under Windows, if the file is not found in this filename, the loader also looks in Windows fonts/ directory. size -: The requested size, in points. index -: Which font face to load (default is first available face). encoding -: Which font encoding to use (default is Unicode). Common encodings are "unic" (Unicode), "symb" (Microsoft Symbol), "ADOB" (Adobe Standard), "ADBE" (Adobe Expert), and "armn" (Apple Roman). layout_engine -: Which layout engine to use, if available: ImageFont.LAYOUT_BASIC or ImageFont.LAYOUT_RAQM. Returns:A font object. Raises:IOError - If the file could not be read. 4.PIL.ImageFont.load_default() Load a "better than nothing" default font. Returns:A font object. Methods 1.PIL.ImageFont.ImageFont.getsize(text, direction=None, features=[], language=None) Returns width and height (in pixels) of given text if rendered in font with provided direction, features, and language. Parameters: text - Text to measure. direction -Direction of the text. It can be 'rtl' (right to left), 'ltr' (left to right) or 'ttb' (top to bottom). Requires libraqm. features - A list of OpenType font features to be used during text layout. This is usually used to turn on optional font features that are not enabled by default, for example 'dlig' or 'ss01', but can be also used to turn off default font features for example '-liga' to disable ligatures or '-kern' to disable kerning.Requires libraqm. language - Language of the text. Different languages may use different glyph shapes or ligatures. This parameter tells the font which language the text is in, and to apply the correct substitutions as appropriate, if available.Requires libraqm. Returns:(width, height) 2.PIL.ImageFont.ImageFont.getmask(text, mode='', direction=None, features=[], language=None) Create a bitmap for the text. If the font uses antialiasing, the bitmap should have mode 'L' and use a maximum value of 255. Otherwise, it should have mode '1'. Parameters: text -: Text to render. mode -:Used by some graphics drivers to indicate what mode the driver prefers; if empty, the renderer may return either mode. Note that the mode is always a string, to simplify C-level implementations. direction -:Direction of the text. It can be 'rtl' (right to left), 'ltr' (left to right) or 'ttb' (top to bottom). Requires libraqm. features - A list of OpenType font features to be used during text layout. This is usually used to turn on optional font features that are not enabled by default, for example 'dlig' or 'ss01', but can be also used to turn off default font features for example '-liga' to disable ligatures or '-kern' to disable kerning.Requires libraqm. language -Language of the text. Different languages may use different glyph shapes or ligatures. This parameter tells the font which language the text is in, and to apply the correct substitutions as appropriate, if available.Requires libraqm. Returns: An internal PIL storage memory instance as defined by the PIL.Image.core interface module.

More Articles of Saurabh Sisodia:

Name Views Likes
Python program to find difference between sums of odd level and even level nodes of a binary tree 750 17
Python Imaging Library(ImagePath Module) 1114 28
Python program to reverse a path in binary search tree using queue 1051 19
Python program to find sum of all the numbers that are formed from root to leaf paths 724 11
Python Imaging Library(ImageFont Module) 1658 27
Python program to find sum of leaf nodes at minimum level 826 16
Python Program to find the closest leaf node to a given node 878 16
Python program to check if given sorted sub-sequence exists in binary search tree 670 11
Python program to find successor for a given key in binary search tree without recursion 740 13
Introduction Of Python Imaging Library (Pillow) 1083 25
Python program to find pairs with given sum such that pair elements lie in different binary search trees 766 22
Python program to find kth ancestor of a node in binary tree 786 20
Python Imaging Library(Image Module) 1519 20
Python program to find the closest leaf in a binary tree 936 22
Python program to find the maximum sum leaf to root path in a binary tree 999 27
Python program to print duplicate elements from the binary search tree 718 15
Python program to find sum of value in each level of binary tree 1108 16
Python program to find distance between two given keys of a binary tree 772 15
Python program to find if there is a triplet in a Balanced binary search tree that adds to zero 919 14
Python Imaging Library(ImageFilter Module) 925 21
Python program to print path from root to a given node in a binary tree 1633 23
Python program to print middle level of perfect binary tree without finding height 697 20
Python Imaging Library(ImageMath Module) 762 20
Python program to find longest consecutive sequence in binary tree 1121 27
Python program to get level of a node in binary tree using recursion 790 15
Python program to count pairs from two binary search trees whose sum is equal to a given value x 691 24
Python program to convert binary tree to binary search tree 719 16
Python Imaging Library(ImageFile Module) 683 11
Python program to print the path common to the two paths from the root to the two given nodes 803 20
Python program to find distance from root to given node in a binary tree 983 15
Python Imaging Library(ExifTags Module) 944 13
Python Imaging Library(ImageSequence Module) 864 25
Python program to check whether a binary tree is a full binary tree or not without using recursion 686 15
Python program to check if a binary tree has duplicate values 1372 24
Python program to find k-th smallest element in binary search tree 772 24
Python Imaging Library(ImageStat Module) 1328 29
Python Imaging Library(ImageEnhance Module) 888 12
Python program to find longest path with same values in a binary tree 943 14
Python program to check if a binary tree is sorted level-wise or not 702 14
Python Imaging Library(ImageColor Module) 791 17
Python Imaging Library(ImageDraw Module) 1500 22
Python Imaging Library(ImageTk Module) 1107 20
Python program to check if a binary tree is subtree of another binary tree 1023 14
Python program to print ancestors of a given node in binary tree 1055 22
Python program to find number of turns to reach from one node to other in binary tree 821 25

Comments