如何将 Font Awesome 转成 PNG 图标 详细教程 含源代码
最近因为项目上需要用到这个字体图标,但是它里面的许多也不能完全满足项目需要,因此就考虑将这个图标导出,然后自己再添加一些其他图标使用
搜索了些解决方案,如:http://www.oschina.net/translate/how-to-convert-font-awesome-to-png-icons,但是上面的步骤过于简单,一个新手完全不会使用,比如Python自己就一点都没接触过,因此自己走了许多弯路。
本文一方面记录以便以后自己再次使用,最重要的是将我自己的每个步骤详细的展现给有需要的大家,希望对大家有帮助。
好 还请留个好评
本文涉及所有资源可以到我的百度云下载:
第一步 下载图标字体源文件:
包含以下文件:
第二步 安装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, re
from os import path, access, R_OK
from PIL import Image, ImageFont, ImageDraw # Support Unicode literals with both Python 2 and 3
if 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 codes
icons = {
"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("\uf1c4"),
"file-sound-o": u("\uf1c7"),
"file-text": u("\uf15c"),
"file-text-o": u("\uf0f6"),
"file-video-o": u("\uf1c8"),
"file-word-o": u("\uf1c2"),
"file-zip-o": u("\uf1c6"),
"files-o": u("\uf0c5"),
"film": u("\uf008"),
"filter": u("\uf0b0"),
"fire": u("\uf06d"),
"fire-extinguisher": u("\uf134"),
"flag": u("\uf024"),
"flag-checkered": u("\uf11e"),
"flag-o": u("\uf11d"),
"flash": u("\uf0e7"),
"flask": u("\uf0c3"),
"flickr": u("\uf16e"),
"floppy-o": u("\uf0c7"),
"folder": u("\uf07b"),
"folder-o": u("\uf114"),
"folder-open": u("\uf07c"),
"folder-open-o": u("\uf115"),
"font": u("\uf031"),
"forward": u("\uf04e"),
"foursquare": u("\uf180"),
"frown-o": u("\uf119"),
"gamepad": u("\uf11b"),
"gavel": u("\uf0e3"),
"gbp": u("\uf154"),
"ge": u("\uf1d1"),
"gear": u("\uf013"),
"gears": u("\uf085"),
"gift": u("\uf06b"),
"git": u("\uf1d3"),
"git-square": u("\uf1d2"),
"github": u("\uf09b"),
"github-alt": u("\uf113"),
"github-square": u("\uf092"),
"gittip": u("\uf184"),
"glass": u("\uf000"),
"globe": u("\uf0ac"),
"google": u("\uf1a0"),
"google-plus": u("\uf0d5"),
"google-plus-square": u("\uf0d4"),
"graduation-cap": u("\uf19d"),
"group": u("\uf0c0"),
"h-square": u("\uf0fd"),
"hacker-news": u("\uf1d4"),
"hand-o-down": u("\uf0a7"),
"hand-o-left": u("\uf0a5"),
"hand-o-right": u("\uf0a4"),
"hand-o-up": u("\uf0a6"),
"hdd-o": u("\uf0a0"),
"header": u("\uf1dc"),
"headphones": u("\uf025"),
"heart": u("\uf004"),
"heart-o": u("\uf08a"),
"history": u("\uf1da"),
"home": u("\uf015"),
"hospital-o": u("\uf0f8"),
"html5": u("\uf13b"),
"image": u("\uf03e"),
"inbox": u("\uf01c"),
"indent": u("\uf03c"),
"info": u("\uf129"),
"info-circle": u("\uf05a"),
"inr": u("\uf156"),
"instagram": u("\uf16d"),
"institution": u("\uf19c"),
"italic": u("\uf033"),
"joomla": u("\uf1aa"),
"jpy": u("\uf157"),
"jsfiddle": u("\uf1cc"),
"key": u("\uf084"),
"keyboard-o": u("\uf11c"),
"krw": u("\uf159"),
"language": u("\uf1ab"),
"laptop": u("\uf109"),
"leaf": u("\uf06c"),
"legal": u("\uf0e3"),
"lemon-o": u("\uf094"),
"level-down": u("\uf149"),
"level-up": u("\uf148"),
"life-bouy": u("\uf1cd"),
"life-ring": u("\uf1cd"),
"life-saver": u("\uf1cd"),
"lightbulb-o": u("\uf0eb"),
"link": u("\uf0c1"),
"linkedin": u("\uf0e1"),
"linkedin-square": u("\uf08c"),
"linux": u("\uf17c"),
"list": u("\uf03a"),
"list-alt": u("\uf022"),
"list-ol": u("\uf0cb"),
"list-ul": u("\uf0ca"),
"location-arrow": u("\uf124"),
"lock": u("\uf023"),
"long-arrow-down": u("\uf175"),
"long-arrow-left": u("\uf177"),
"long-arrow-right": u("\uf178"),
"long-arrow-up": u("\uf176"),
"magic": u("\uf0d0"),
"magnet": u("\uf076"),
"mail-forward": u("\uf064"),
"mail-reply": u("\uf112"),
"mail-reply-all": u("\uf122"),
"male": u("\uf183"),
"map-marker": u("\uf041"),
"maxcdn": u("\uf136"),
"medkit": u("\uf0fa"),
"meh-o": u("\uf11a"),
"microphone": u("\uf130"),
"microphone-slash": u("\uf131"),
"minus": u("\uf068"),
"minus-circle": u("\uf056"),
"minus-square": u("\uf146"),
"minus-square-o": u("\uf147"),
"mobile": u("\uf10b"),
"mobile-phone": u("\uf10b"),
"money": u("\uf0d6"),
"moon-o": u("\uf186"),
"mortar-board": u("\uf19d"),
"music": u("\uf001"),
"navicon": u("\uf0c9"),
"openid": u("\uf19b"),
"outdent": u("\uf03b"),
"pagelines": u("\uf18c"),
"paper-plane": u("\uf1d8"),
"paper-plane-o": u("\uf1d9"),
"paperclip": u("\uf0c6"),
"paragraph": u("\uf1dd"),
"paste": u("\uf0ea"),
"pause": u("\uf04c"),
"paw": u("\uf1b0"),
"pencil": u("\uf040"),
"pencil-square": u("\uf14b"),
"pencil-square-o": u("\uf044"),
"phone": u("\uf095"),
"phone-square": u("\uf098"),
"photo": u("\uf03e"),
"picture-o": u("\uf03e"),
"pied-piper": u("\uf1a7"),
"pied-piper-alt": u("\uf1a8"),
"pied-piper-square": u("\uf1a7"),
"pinterest": u("\uf0d2"),
"pinterest-square": u("\uf0d3"),
"plane": u("\uf072"),
"play": u("\uf04b"),
"play-circle": u("\uf144"),
"play-circle-o": u("\uf01d"),
"plus": u("\uf067"),
"plus-circle": u("\uf055"),
"plus-square": u("\uf0fe"),
"plus-square-o": u("\uf196"),
"power-off": u("\uf011"),
"print": u("\uf02f"),
"puzzle-piece": u("\uf12e"),
"qq": u("\uf1d6"),
"qrcode": u("\uf029"),
"question": u("\uf128"),
"question-circle": u("\uf059"),
"quote-left": u("\uf10d"),
"quote-right": u("\uf10e"),
"ra": u("\uf1d0"),
"random": u("\uf074"),
"rebel": u("\uf1d0"),
"recycle": u("\uf1b8"),
"reddit": u("\uf1a1"),
"reddit-square": u("\uf1a2"),
"refresh": u("\uf021"),
"renren": u("\uf18b"),
"reorder": u("\uf0c9"),
"repeat": u("\uf01e"),
"reply": u("\uf112"),
"reply-all": u("\uf122"),
"retweet": u("\uf079"),
"rmb": u("\uf157"),
"road": u("\uf018"),
"rocket": u("\uf135"),
"rotate-left": u("\uf0e2"),
"rotate-right": u("\uf01e"),
"rouble": u("\uf158"),
"rss": u("\uf09e"),
"rss-square": u("\uf143"),
"rub": u("\uf158"),
"ruble": u("\uf158"),
"rupee": u("\uf156"),
"save": u("\uf0c7"),
"scissors": u("\uf0c4"),
"search": u("\uf002"),
"search-minus": u("\uf010"),
"search-plus": u("\uf00e"),
"send": u("\uf1d8"),
"send-o": u("\uf1d9"),
"share": u("\uf064"),
"share-alt": u("\uf1e0"),
"share-alt-square": u("\uf1e1"),
"share-square": u("\uf14d"),
"share-square-o": u("\uf045"),
"shield": u("\uf132"),
"shopping-cart": u("\uf07a"),
"sign-in": u("\uf090"),
"sign-out": u("\uf08b"),
"signal": u("\uf012"),
"sitemap": u("\uf0e8"),
"skype": u("\uf17e"),
"slack": u("\uf198"),
"sliders": u("\uf1de"),
"smile-o": u("\uf118"),
"sort": u("\uf0dc"),
"sort-alpha-asc": u("\uf15d"),
"sort-alpha-desc": u("\uf15e"),
"sort-amount-asc": u("\uf160"),
"sort-amount-desc": u("\uf161"),
"sort-asc": u("\uf0de"),
"sort-desc": u("\uf0dd"),
"sort-down": u("\uf0dd"),
"sort-numeric-asc": u("\uf162"),
"sort-numeric-desc": u("\uf163"),
"sort-up": u("\uf0de"),
"soundcloud": u("\uf1be"),
"space-shuttle": u("\uf197"),
"spinner": u("\uf110"),
"spoon": u("\uf1b1"),
"spotify": u("\uf1bc"),
"square": u("\uf0c8"),
"square-o": u("\uf096"),
"stack-exchange": u("\uf18d"),
"stack-overflow": u("\uf16c"),
"star": u("\uf005"),
"star-half": u("\uf089"),
"star-half-empty": u("\uf123"),
"star-half-full": u("\uf123"),
"star-half-o": u("\uf123"),
"star-o": u("\uf006"),
"steam": u("\uf1b6"),
"steam-square": u("\uf1b7"),
"step-backward": u("\uf048"),
"step-forward": u("\uf051"),
"stethoscope": u("\uf0f1"),
"stop": u("\uf04d"),
"strikethrough": u("\uf0cc"),
"stumbleupon": u("\uf1a4"),
"stumbleupon-circle": u("\uf1a3"),
"subscript": u("\uf12c"),
"suitcase": u("\uf0f2"),
"sun-o": u("\uf185"),
"superscript": u("\uf12b"),
"support": u("\uf1cd"),
"table": u("\uf0ce"),
"tablet": u("\uf10a"),
"tachometer": u("\uf0e4"),
"tag": u("\uf02b"),
"tags": u("\uf02c"),
"tasks": u("\uf0ae"),
"taxi": u("\uf1ba"),
"tencent-weibo": u("\uf1d5"),
"terminal": u("\uf120"),
"text-height": u("\uf034"),
"text-width": u("\uf035"),
"th": u("\uf00a"),
"th-large": u("\uf009"),
"th-list": u("\uf00b"),
"thumb-tack": u("\uf08d"),
"thumbs-down": u("\uf165"),
"thumbs-o-down": u("\uf088"),
"thumbs-o-up": u("\uf087"),
"thumbs-up": u("\uf164"),
"ticket": u("\uf145"),
"times": u("\uf00d"),
"times-circle": u("\uf057"),
"times-circle-o": u("\uf05c"),
"tint": u("\uf043"),
"toggle-down": u("\uf150"),
"toggle-left": u("\uf191"),
"toggle-right": u("\uf152"),
"toggle-up": u("\uf151"),
"trash-o": u("\uf014"),
"tree": u("\uf1bb"),
"trello": u("\uf181"),
"trophy": u("\uf091"),
"truck": u("\uf0d1"),
"try": u("\uf195"),
"tumblr": u("\uf173"),
"tumblr-square": u("\uf174"),
"turkish-lira": u("\uf195"),
"twitter": u("\uf099"),
"twitter-square": u("\uf081"),
"umbrella": u("\uf0e9"),
"underline": u("\uf0cd"),
"undo": u("\uf0e2"),
"university": u("\uf19c"),
"unlink": u("\uf127"),
"unlock": u("\uf09c"),
"unlock-alt": u("\uf13e"),
"unsorted": u("\uf0dc"),
"upload": u("\uf093"),
"usd": u("\uf155"),
"user": u("\uf007"),
"user-md": u("\uf0f0"),
"users": u("\uf0c0"),
"video-camera": u("\uf03d"),
"vimeo-square": u("\uf194"),
"vine": u("\uf1ca"),
"vk": u("\uf189"),
"volume-down": u("\uf027"),
"volume-off": u("\uf026"),
"volume-up": u("\uf028"),
"warning": u("\uf071"),
"wechat": u("\uf1d7"),
"weibo": u("\uf18a"),
"weixin": u("\uf1d7"),
"wheelchair": u("\uf193"),
"windows": u("\uf17a"),
"won": u("\uf159"),
"wordpress": u("\uf19a"),
"wrench": u("\uf0ad"),
"xing": u("\uf168"),
"xing-square": u("\uf169"),
"yahoo": u("\uf19e"),
"yen": u("\uf157"),
"youtube": u("\uf167"),
"youtube-play": u("\uf16a"),
"youtube-square": u("\uf166"),
} class ListAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
for icon in sorted(icons.keys()):
print(icon)
exit(0) class ListUpdateAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
print("icons = {")
for icon in sorted(icons.keys()):
print(u' "%s": u("\\u%x"),' % (icon, ord(icons[icon])))
print("}")
exit(0) def export_icon(icon, size, filename, font, color):
image = Image.new("RGBA", (size, size), color=(0,0,0,0)) draw = ImageDraw.Draw(image) # Initialize font
font = ImageFont.truetype(font, size) # Determine the dimensions of the icon
width,height = draw.textsize(icons[icon], font=font) draw.text(((size - width) / 2, (size - height) / 2), icons[icon],
font=font, fill=color) # Get bounding box
bbox = image.getbbox() # Create an alpha mask
imagemask = Image.new("L", (size, size), 0)
drawmask = ImageDraw.Draw(imagemask) # Draw the icon on the mask
drawmask.text(((size - width) / 2, (size - height) / 2), icons[icon],
font=font, fill=255) # Create a solid color image and apply the mask
iconimage = Image.new("RGBA", (size,size), color)
iconimage.putalpha(imagemask) if bbox:
iconimage = iconimage.crop(bbox) borderw = int((size - (bbox[2] - bbox[0])) / 2)
borderh = int((size - (bbox[3] - bbox[1])) / 2) # Create output image
outimage = Image.new("RGBA", (size, size), (0,0,0,0))
outimage.paste(iconimage, (borderw,borderh)) # Save file
outimage.save(filename) class LoadCSSAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
global icons
icons = LoadCSSAction._load_css(values) @staticmethod
def _load_css(filename):
import tinycss
new_icons = {}
parser = tinycss.make_parser("page3") try:
stylesheet = parser.parse_stylesheet_file(filename)
except IOError:
print >> sys.stderr, ("Error: CSS file (%s) can't be opened"
% (filename))
exit(1) is_icon = re.compile(u("\.fa-(.*):before,?"))
for rule in stylesheet.rules:
selector = rule.selector.as_css()
for match in is_icon.finditer(selector):
name = match.groups()[0]
for declaration in rule.declarations:
if declaration.name == u"content":
val = declaration.value.as_css()
if val.startswith('"') and val.endswith('"'):
val = val[1:-1]
new_icons[name] = uchr(int(val[1:], 16))
return new_icons if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="Exports Font Awesome icons as PNG images.") parser.add_argument("icon", type=str, nargs="+",
help="The name(s) of the icon(s) to export (or \"ALL\" for all icons)")
parser.add_argument("--color", type=str, default="black",
help="Color (HTML color code or name, default: black)")
parser.add_argument("--filename", type=str,
help="The name of the output file (it must end with \".png\"). If " +
"all files are exported, it is used as a prefix.")
parser.add_argument("--font", type=str, default="fontawesome-webfont.ttf",
help="Font file to use (default: fontawesome-webfont.ttf)")
parser.add_argument("--css", type=str, default="", action=LoadCSSAction,
help="Path to the CSS file defining icon names (instead of the " +
"predefined list)")
parser.add_argument("--list", nargs=0, action=ListAction,
help="List available icon names and exit")
parser.add_argument("--list-update", nargs=0, action=ListUpdateAction,
help=argparse.SUPPRESS)
parser.add_argument("--size", type=int, default=16,
help="Icon size in pixels (default: 16)") args = parser.parse_args()
icon = args.icon
size = args.size
font = args.font
color = args.color if args.font:
if not path.isfile(args.font) or not access(args.font, R_OK):
print >> sys.stderr, ("Error: Font file (%s) can't be opened"
% (args.font))
exit(1) if args.icon == [ "ALL" ]:
# Export all icons
selected_icons = sorted(icons.keys())
else:
selected_icons = [] # Icon name was given
for icon in args.icon:
# Strip the "icon-" prefix, if present
if icon.startswith("icon-"):
icon = icon[5:] if icon in icons:
selected_icons.append(icon)
else:
print >> sys.stderr, "Error: Unknown icon name (%s)" % (icon)
sys.exit(1) for icon in selected_icons:
if len(selected_icons) > 1:
# Exporting multiple icons -- treat the filename option as name prefix
filename = (args.filename or "") + icon + ".png"
else:
# Exporting one icon
if args.filename:
filename = args.filename
else:
filename = icon + ".png" print("Exporting icon \"%s\" as %s (%ix%i pixels)" %
(icon, filename, size, size)) export_icon(icon, size, filename, font, color)
帮助文档 README.md:
Font Awesome to PNG
=================== This program allows you to extract the awesome
[Font Awesome] (http://fortawesome.github.com/Font-Awesome/) icons as PNG images
of specified size. ### Usage font-awesome-to-png.py [-h] [--color COLOR] [--filename FILENAME]
[--font FONT] [--css CSS] [--list] [--size SIZE]
icon [icon ...] positional arguments:
icon The name(s) of the icon(s) to export (or "ALL" for
all icons) optional arguments:
--color COLOR Color (HTML color code or name, default: black)
--filename FILENAME The name of the output file (it must end with
".png"). If all files are exported, it is used as a
prefix.
--font FONT Font file to use (default: fontawesome-webfont.ttf)
--css CSS Path to the CSS file defining icon names (instead of
the predefined list)
--list List available icon names and exit
--size SIZE Icon size in pixels (default: 16) hidden optional arguments:
--list-update List available icon names and codes in format suitable
for updating the program source. To use the program, you need the Font Awesome TTF file, which is available in
[Font Awesome Github repository] (https://github.com/FortAwesome/Font-Awesome). The internal icon list is matched to Font Awesome 4.1.0. To use a later/different
version, use font-awesome.css from the Font Awesome GitHub repository. ### Examples Export the "play" and "stop" icons as 24x24 pixels images: font-awesome-to-png.py --size 24 play stop Export the asterisk icon as 32x32 pixels image, in blue: font-awesome-to-png.py --size 32 --color blue asterisk Export all icons as 16x16 pixels images: font-awesome-to-png.py ALL
如何将 Font Awesome 转成 PNG 图标 详细教程 含源代码的更多相关文章
- Java项目打包成exe的详细教程
Java项目打包成exe的详细教程 把Java项目打包成exe共分为以下两步: 1. 利用Eclipse先把Java项目先打成jar包 2. 利用exe4j工具把jar包转成exe 这里以Java项目 ...
- 自定义Sublime Text图标详细教程
改造后的Sublime 先看看我改造后的神器图标,接下来你就知道下面是干什么的了 : 之前无意间在刘哇勇的博客上看到这么一篇文章,很好奇就尝试着更改Sublime Text ...
- 如何将svg图标快速转换成字体图标?
今天遇到一个客户需要我将页面的图标做成字体图标,想想哎可能整的麻烦,不过想想这也是对项目的一个优化 ( 1.字体图标直接用color自由控制颜色:2.整合在一起,减少http请求等 PS:平时 ...
- Font Awesome-用CSS实现各种小图标icon
Font Awesome为您提供可缩放的矢量图标,您可以使用CSS所提供的所有特性对它们进行更改,包括:大小.颜色.阴影或者其它任何支持的效果.官网:http://fontawesome.dashga ...
- 使用Font Awesome替换EasyUI的图标
用过EasyUI的朋友都知道,大部分组件都有一个iconCls属性,用于显示一个图标.但是EasyUI自带图标数量少.不美观,于是想到了使用Font Awesome来更换和拓展这些图标. 先看看Eas ...
- [工具-002]把png图片转换成ico图标
最近我收到了上级的一个需求,我们需要使用产品的png图片,批量转换成ico图片,然后调用上一篇的方法,替换可执行程序的图标.一开始查看资料的时候,C#有直接可以转成ico图片的方法,很简单.但是生成的 ...
- 为网站文字前面添加图标 在线调用 Font Awesome 字体icon小图标 美化网站
一.如何开始 1.将下面的代码复制粘贴到HTML页面面的 <head> 下面 <link rel="stylesheet" href="https:// ...
- 关于font awesome或Glyphicons字体图标不能正确显示的问题
此处讨论的是关于本地字体的安装和引进 实际操作经验中,某些网站模板设置的CSS, FONTS目录较深,如果按默认的路径设置,字体图标死活都不会显示. 解决办法是将FONTS目录,安装在网站根目录下 C ...
- 第二十七篇 -- 如何给静态文本设置成ico图标形式以及如何修改文本框中的内容
修改静态文本框内容: CWnd* pWnd = GetDlgItem(IDC_STATIC1); pWnd->SetWindowText(_T("Server is on!" ...
随机推荐
- Light oj 1197 - Help Hanzo (素数筛技巧)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1197 给你a和b求a到b之间的素数个数. 先在小区间素数筛,大区间就用类似素数筛的想法 ...
- android中的Cursor类
转载: 使用过 SQLite 数据库的童鞋对 Cursor 应该不陌生,如果你是搞.net 开发你大可以把Cursor理解成 Ado.net 中的数据集合相当于dataReader.今天特地将它单独拿 ...
- jq简单选项卡
function tabControl(obj,elm){ $(obj).hover(function(){ $(this).addClass('active').siblings().removeC ...
- Js面向对象和数据类型内存分配(转)
一 Js基本数据类型以及内存情况 1 Undefined Undefined类型只有一个值undefined,在使用了声明但未初始化的变量的时候,这个变量值就是undefined 1 var hi; ...
- C#客户端链接网页需要用到的WebClient
WebClient 类提供向 URI 标识的任何本地.Intranet 或 Internet 资源发送数据以及从这些资源接收数据的公共方法. WebClient 类使用 WebRequest 类提供对 ...
- 教你看懂邮件头信息<转载>
MIME对于邮件系统的扩展是巨大的,因为在MIME出现以前,信件内容如果要包括声音和动画,就必须把它变为ASCII码或把二进制的信息变成可以传送的编码标准,而接收方必须经过解码才可以获得声音和图画信息 ...
- CentOS 6.5安装MySQL中文乱码问题解决
不管是Linux还是Windows都有新手遇到MySQL服务安装好了之后写入中文发现乱码,今天我装了个CentOS 6.5也遇到了这个问题,现在解决了,分享一下经验. 1.首先安装mysql,我很怕麻 ...
- Codeforces Gym 100610 Problem E. Explicit Formula 水题
Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- strassen algorithm
the explaination that is clear in my view is from wiki.
- SQL Server中内连接和外连接的区别
SQL Server中内连接和外连接的区别 假设一个数据库中有两张表,一张是学生表StudentInfo,一张是班级表ClassInfo,两张表之间用ClassId字段进行关联. 如果用内连接,正常的 ...