def apply(self, info, glyph, startx, starty, size, maxsize, glyphimage, previmage): factor = self.factor face = info.face flags = ft.LOAD_RENDER | ft.LOAD_TARGET_MONO face.set_char_size( width=0, height=(info.size*factor)*64, hres=info.dpi, vres=info.dpi ) face.load_char( glyph.unicode, flags ) bitmap = fu.make_array_from_bitmap(face.glyph.contents.bitmap) * 255 metrics = face.glyph.contents.metrics bearingY = (metrics.horiBearingY >> 6) + info.internalpadding[1]*factor + info.extrapadding[1]*factor # Due to the down scaling, we need to make sure that the bitmap start at the correct pixels offset_y = bearingY - glyph.bearingY * factor bitmap = fu.pad_bitmap(bitmap, info.extrapadding[0]*factor, info.extrapadding[1]*factor - offset_y, info.extrapadding[2]*factor, info.extrapadding[3]*factor + offset_y, 0, debug=glyph.unicode=='r') # TODO: Work out how to eliminate this issue e = np.empty( bitmap.shape, bitmap.dtype, order='F' ) e[:, :] = bitmap bitmap = e i = utils.calculate_sedt(bitmap, self.size) #i = bitmap while factor > 1: i = utils.half_size(i) factor /= 2 i = i.astype(np.float64) / 255.0 a = np.zeros_like(i) a[i > 0] = 1.0 return np.dstack( (i, i, i, a) )
r, g, b, a = (image[:, :, 0], image[:, :, 1], image[:, :, 2], image[:, :, 3]) image = np.dstack((r, g, b, a)) kernel = create_2d_circle_kernel(5) out = utils.maximum(image, kernel) outim = Image.fromarray(out) outim.save('/Users/mawe/Pictures/a_outline.png') out = blur_image(image, 10) outim = Image.fromarray(out) outim.save('/Users/mawe/Pictures/a_blur.png') """ im = Image.open('/Users/mawe/Pictures/a.png') image = np.array(im.getdata(), np.uint8).reshape(im.size[1], im.size[0], 4) image = np.dstack((image[:, :, 0],)) out = utils.calculate_sedt(image, 14) outim = Image.fromarray( np.dstack( (out, out, out, np.ones_like(out)*255 ) ) ) #outim = Image.fromarray( out ) outim.save('build/a_sed.png') # http://code.google.com/p/freetype-gl/