示例#1
0
    def __init__(self, *k, **kw):
        options = k[0]
        for name, value in kw.iteritems():
            try:
                setattr(self, name, eval(value) )
            except NameError:
                setattr(self, name, value )
            except SyntaxError:
                if value and value[0] == '.':  # relative paths are ok
                    setattr(self, name, value )
                else:
                    raise

        if not os.path.exists( os.path.join(options.datadir, self.name)):
            raise fu.FontException("No such file: %s  in dir %s" % (self.name, options.datadir))

        self.bitmap = np.asarray( Image.open( os.path.join(options.datadir, self.name) ), float) / 255.0

        if self.bitmap.shape[2] == 3:
            r, g, b = fu.split_channels(self.bitmap)
            a = np.ones_like(r)
            #self.bitmap = np.dstack((r, g, b, a))
        else:
            r, g, b, a = fu.split_channels(self.bitmap)
        self.bitmap = np.dstack( (r.T, g.T, b.T, a.T) )
示例#2
0
    def apply(self, info, glyph, image):        
        out = utils.maximum(image, self.kernel)
        
        if self.spread:
            out = fu.blur_image(out, self.spread)
        
        r, g, b, a = fu.split_channels(out)
        
        r[a > 0] = self.color[0]
        g[a > 0] = self.color[1]
        b[a > 0] = self.color[2]
        a[a > 0] = self.opacity

        return fu.alpha_blend(out, image)
示例#3
0
    def apply(self, info, glyph, image):
        x = int(self.offsetx)
        y = -int(self.offsety)

        shadowbitmap = np.copy( image )
        shadowbitmap = np.roll(shadowbitmap, x, axis = 0)
        shadowbitmap = np.roll(shadowbitmap, y, axis = 1)

        # replace the color
        r, g, b, a = fu.split_channels(shadowbitmap)

        shadowbitmap = np.dstack( (r, g, b, a) ) * (self.color[0], self.color[1], self.color[2], self.opacity)

        shadowbitmap = fu.blur_image(shadowbitmap, self.size)

        topbitmap = np.zeros_like( shadowbitmap )
        topbitmap[:image.shape[0], :image.shape[1], :] = image

        return fu.alpha_blend(shadowbitmap, topbitmap)