'This method converts an unicode character to an image (using Font
Awesome font by default) and is used only for mass mailing because
custom fonts are not supported in mail.
:param icon : decimal encoding of unicode character
:param color : RGB code of the color
:param size : Pixels in integer
:param alpha : transparency of the image from 0 to 255
:param font : font path
:returns PNG image converted from given font'

@http.route(['/web_editor/font_to_img/<icon>', '/web_editor/font_to_img/<icon>/<color>', '/web_editor/font_to_img/<icon>/<color>/<int:size>', '/web_editor/font_to_img/<icon>/<color>/<int:size>/<int:alpha>'], type='http', auth='none')
def export_icon_to_png(self, icon, color='#000', size=100, alpha=255, font='/web/static/lib/fontawesome/fonts/fontawesome-webfont.ttf'):

    size = max(1, size)
    addons_path = http.addons_manifest['web']['addons_path']
    font_obj = ImageFont.truetype((addons_path + font), size)
    icon = (unichr(int(icon)) if icon.isdigit() else icon)
    image = Image.new('RGBA', (size, size), color=(0, 0, 0, 0))
    draw = ImageDraw.Draw(image)
    (boxw, boxh) = draw.textsize(icon, font=font_obj)
    draw.text((0, 0), icon, font=font_obj)
    (left, top, right, bottom) = image.getbbox()
    imagemask = Image.new('L', (boxw, boxh), 0)
    drawmask = ImageDraw.Draw(imagemask)
    drawmask.text(((- left), (- top)), icon, font=font_obj, fill=alpha)
    if color.startswith('rgba'):
        color = color.replace('rgba', 'rgb')
        color = (','.join(color.split(',')[:(-1)]) + ')')
    iconimage = Image.new('RGBA', (boxw, boxh), color)
    iconimage.putalpha(imagemask)
    outimage = Image.new('RGBA', (boxw, size), (0, 0, 0, 0))
    outimage.paste(iconimage, (left, top))
    output = io.BytesIO()
    outimage.save(output, format='PNG')
    response = werkzeug.wrappers.Response()
    response.mimetype = 'image/png'
    response.data = output.getvalue()
    response.headers['Cache-Control'] = 'public,    max-age=604800'
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Methods'] = 'GET,    POST'
    response.headers['Connection'] = 'close'
    response.headers['Date'] = time.strftime('%a,    %d-%b-%Y    %T    GMT', time.gmtime())
    response.headers['Expires'] = time.strftime('%a,    %d-%b-%Y    %T    GMT', time.gmtime((time.time() + (604800 * 60))))
    return response
