首页 > 网站 > WEB开发 > 正文

如何将 Font Awesome 转成 PNG 图标 详细教程 含源代码

2024-04-27 14:25:25
字体:
来源:转载
供稿:网友
如何将 Font Awesome 转成 PNG 图标 详细教程 含源代码

最近因为项目上需要用到这个字体图标,但是它里面的许多也不能完全满足项目需要,因此就考虑将这个图标导出,然后自己再添加一些其他图标使用

搜索了些解决方案,如:http://www.oschina.net/translate/how-to-convert-font-awesome-to-png-icons,但是上面的步骤过于简单,一个新手完全不会使用,比如Python自己就一点都没接触过,因此自己走了许多弯路。

本文一方面记录以便以后自己再次使用,最重要的是将我自己的每个步骤详细的展现给有需要的大家,希望对大家有帮助。

好 还请留个好评

本文涉及所有资源可以到我的百度云下载:

font-awesome-to-png

第一步 下载图标字体源文件:

包含以下文件:

第二步 安装python-2.7.9(我电脑是64位的,截图也是64位,实际上只能安装32位,64位图标处理库(第二部会安装以处理图片)找不到安装路径,安装过程是一样的)

第三步 安装图形处理库

安装完成后:菜单》全部程序》 Python 2.7发现已经安装成功

第四部 你下载文件里面有个 目录font-awesome-to-png 里面有将会使用的脚本文件和字体文件(也是你第一步下载的文件)

来点其他参数

颜色变了,证明其他参数也是可靠的,大功告成。

源代码1 font-awesome-to-png.py:

#!/usr/bin/env python## font-awesome-to-png.py## Exports Font Awesome icons as PNG images.## Copyright (c) 2012-2014 Michal Wojciechowski (http://odyniec.net/)## Font Awesome - http://fortawesome.github.com/Font-Awesome#import sys, argparse, refrom os import path, access, R_OKfrom PIL import Image, ImageFont, ImageDraw# Support Unicode literals with both Python 2 and 3if sys.version < '3':    import codecs    def u(x):        return codecs.unicode_escape_decode(x)[0]    def uchr(x):        return unichr(x)else:    def u(x):        return x    def uchr(x):        return chr(x)# Mapping of icon names to character codesicons = {    "adjust": u("/uf042"),    "adn": u("/uf170"),    "align-center": u("/uf037"),    "align-justify": u("/uf039"),    "align-left": u("/uf036"),    "align-right": u("/uf038"),    "ambulance": u("/uf0f9"),    "anchor": u("/uf13d"),    "android": u("/uf17b"),    "angle-double-down": u("/uf103"),    "angle-double-left": u("/uf100"),    "angle-double-right": u("/uf101"),    "angle-double-up": u("/uf102"),    "angle-down": u("/uf107"),    "angle-left": u("/uf104"),    "angle-right": u("/uf105"),    "angle-up": u("/uf106"),    "apple": u("/uf179"),    "archive": u("/uf187"),    "arrow-circle-down": u("/uf0ab"),    "arrow-circle-left": u("/uf0a8"),    "arrow-circle-o-down": u("/uf01a"),    "arrow-circle-o-left": u("/uf190"),    "arrow-circle-o-right": u("/uf18e"),    "arrow-circle-o-up": u("/uf01b"),    "arrow-circle-right": u("/uf0a9"),    "arrow-circle-up": u("/uf0aa"),    "arrow-down": u("/uf063"),    "arrow-left": u("/uf060"),    "arrow-right": u("/uf061"),    "arrow-up": u("/uf062"),    "arrows": u("/uf047"),    "arrows-alt": u("/uf0b2"),    "arrows-h": u("/uf07e"),    "arrows-v": u("/uf07d"),    "asterisk": u("/uf069"),    "automobile": u("/uf1b9"),    "backward": u("/uf04a"),    "ban": u("/uf05e"),    "bank": u("/uf19c"),    "bar-chart-o": u("/uf080"),    "barcode": u("/uf02a"),    "bars": u("/uf0c9"),    "beer": u("/uf0fc"),    "behance": u("/uf1b4"),    "behance-square": u("/uf1b5"),    "bell": u("/uf0f3"),    "bell-o": u("/uf0a2"),    "bitbucket": u("/uf171"),    "bitbucket-square": u("/uf172"),    "bitcoin": u("/uf15a"),    "bold": u("/uf032"),    "bolt": u("/uf0e7"),    "bomb": u("/uf1e2"),    "book": u("/uf02d"),    "bookmark": u("/uf02e"),    "bookmark-o": u("/uf097"),    "briefcase": u("/uf0b1"),    "btc": u("/uf15a"),    "bug": u("/uf188"),    "building": u("/uf1ad"),    "building-o": u("/uf0f7"),    "bullhorn": u("/uf0a1"),    "bullseye": u("/uf140"),    "cab": u("/uf1ba"),    "calendar": u("/uf073"),    "calendar-o": u("/uf133"),    "camera": u("/uf030"),    "camera-retro": u("/uf083"),    "car": u("/uf1b9"),    "caret-down": u("/uf0d7"),    "caret-left": u("/uf0d9"),    "caret-right": u("/uf0da"),    "caret-square-o-down": u("/uf150"),    "caret-square-o-left": u("/uf191"),    "caret-square-o-right": u("/uf152"),    "caret-square-o-up": u("/uf151"),    "caret-up": u("/uf0d8"),    "certificate": u("/uf0a3"),    "chain": u("/uf0c1"),    "chain-broken": u("/uf127"),    "check": u("/uf00c"),    "check-circle": u("/uf058"),    "check-circle-o": u("/uf05d"),    "check-square": u("/uf14a"),    "check-square-o": u("/uf046"),    "chevron-circle-down": u("/uf13a"),    "chevron-circle-left": u("/uf137"),    "chevron-circle-right": u("/uf138"),    "chevron-circle-up": u("/uf139"),    "chevron-down": u("/uf078"),    "chevron-left": u("/uf053"),    "chevron-right": u("/uf054"),    "chevron-up": u("/uf077"),    "child": u("/uf1ae"),    "circle": u("/uf111"),    "circle-o": u("/uf10c"),    "circle-o-notch": u("/uf1ce"),    "circle-thin": u("/uf1db"),    "clipboard": u("/uf0ea"),    "clock-o": u("/uf017"),    "cloud": u("/uf0c2"),    "cloud-download": u("/uf0ed"),    "cloud-upload": u("/uf0ee"),    "cny": u("/uf157"),    "code": u("/uf121"),    "code-fork": u("/uf126"),    "codepen": u("/uf1cb"),    "coffee": u("/uf0f4"),    "cog": u("/uf013"),    "cogs": u("/uf085"),    "columns": u("/uf0db"),    "comment": u("/uf075"),    "comment-o": u("/uf0e5"),    "comments": u("/uf086"),    "comments-o": u("/uf0e6"),    "compass": u("/uf14e"),    "comPRess": u("/uf066"),    "copy": u("/uf0c5"),    "credit-card": u("/uf09d"),    "crop": u("/uf125"),    "crosshairs": u("/uf05b"),    "CSS3": u("/uf13c"),    "cube": u("/uf1b2"),    "cubes": u("/uf1b3"),    "cut": u("/uf0c4"),    "cutlery": u("/uf0f5"),    "dashboard": u("/uf0e4"),    "database": u("/uf1c0"),    "dedent": u("/uf03b"),    "delicious": u("/uf1a5"),    "desktop": u("/uf108"),    "deviantart": u("/uf1bd"),    "digg": u("/uf1a6"),    "dollar": u("/uf155"),    "dot-circle-o": u("/uf192"),    "download": u("/uf019"),    "dribbble": u("/uf17d"),    "dropbox": u("/uf16b"),    "drupal": u("/uf1a9"),    "edit": u("/uf044"),    "eject": u("/uf052"),    "ellipsis-h": u("/uf141"),    "ellipsis-v": u("/uf142"),    "empire": u("/uf1d1"),    "envelope": u("/uf0e0"),    "envelope-o": u("/uf003"),    "envelope-square": u("/uf199"),    "eraser": u("/uf12d"),    "eur": u("/uf153"),    "euro": u("/uf153"),    "exchange": u("/uf0ec"),    "exclamation": u("/uf12a"),    "exclamation-circle": u("/uf06a"),    "exclamation-triangle": u("/uf071"),    "expand": u("/uf065"),    "external-link": u("/uf08e"),    "external-link-square": u("/uf14c"),    "eye": u("/uf06e"),    "eye-slash": u("/uf070"),    "facebook": u("/uf09a"),    "facebook-square": u("/uf082"),    "fast-backward": u("/uf049"),    "fast-forward": u("/uf050"),    "fax": u("/uf1ac"),    "female": u("/uf182"),    "fighter-jet": u("/uf0fb"),    "file": u("/uf15b"),    "file-archive-o": u("/uf1c6"),    "file-audio-o": u("/uf1c7"),    "file-code-o": u("/uf1c9"),    "file-Excel-o": u("/uf1c3"),    "file-image-o": u("/uf1c5"),    "file-movie-o": u("/uf1c8"),    "file-o": u("/uf016"),    "file-pdf-o": u("/uf1c1"),    "file-photo-o": u("/uf1c5"),    "file-picture-o": u("/uf1c5"),    "file-Powerpoint-o": u("/
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表