5.12. fontutils

Copyright @ 2013 Mathias Westerdahl

fontutils.alpha_blend(bottom, top)[source]

Creates a new copy by alpha blending top onto bottom

Parameters:
  • bottom – A numpy array of shape (x, y, 4)
  • top – A numpy array of shape (x, y, 4)
Returns:

Returns a new numpy.array with the same dtype as the top array

fontutils.create_1d_gaussian_kernel(radius, sigma=None)[source]

Creates a 1D gaussian kernel given a radius and a constant Implementation taken from http://en.wikipedia.org/wiki/Gaussian_blur

Parameters:
  • radius – The radius of the kernel
  • a – A constant that controls the shape of the bell curve
Returns:

A 1D numpy.array with shape (radius*2+1,)

fontutils.create_2d_circle_kernel(radius)[source]

Creates a kernel where the cells within the radius gets a value of 1.0

Parameters:radius – The radius of the kernel
Returns:A numpy.array with shape (radius*2+1, radius*2+1)
fontutils.make_array_from_bitmap(_bitmap, bitdepth=8)[source]

Converts a FTBitmap into a numpy array

fontutils.pad_bitmap(bitmap, left, top, right, bottom, value, debug=False)[source]

Pads a bitmap with pixels on each side. The new cells are applied the value

Parameters:
  • bitmap – A numpy array
  • left – The number of pixels that should be added to the left
  • top – The number of pixels that should be added to the top
  • right – The number of pixels that should be added to the right
  • bottom – The number of pixels that should be added to the bottom
  • value – The value to insert
Returns:

The padded numpy array

fontutils.print_ascii(bitmap, char=None, replace=['.', '@'])[source]

For debugging the contents of a numpy bitmap

Parameters:
  • bitmap – A 2-D numpy bitmap of dimensions (e.g. bitmap.shape == (X,Y))
  • char – A CharacterInfo
  • replace

    A 2 element array that lets you replace the bitmap values with better suited ascii characters. Can be None, then the original values will be printed. Rule:

    replace[1] if bitmap[x,y] else replace[0]
    
fontutils.split_channels(image)[source]

Takes a numpy array and splits its’ channels into a 3 or 4 tuple (views)

Returns:A 3 or 4 tuple, with each element containing the corresponding color channel