最近因为项目上需要用到这个字体图标,但是它里面的许多也不能完全满足项目需要,因此就考虑将这个图标导出,然后自己再添加一些其他图标使用
搜索了些解决方案,如: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:
013 | import sys, argparse, re |
014 | from os import path, access, R_OK |
015 | from PIL import Image, ImageFont, ImageDraw |
021 | return codecs.unicode_escape_decode(x)[ 0 ] |
034 | "adjust" : u( "\uf042" ), |
036 | "align-center" : u( "\uf037" ), |
037 | "align-justify" : u( "\uf039" ), |
038 | "align-left" : u( "\uf036" ), |
039 | "align-right" : u( "\uf038" ), |
040 | "ambulance" : u( "\uf0f9" ), |
041 | "anchor" : u( "\uf13d" ), |
042 | "android" : u( "\uf17b" ), |
043 | "angle-double-down" : u( "\uf103" ), |
044 | "angle-double-left" : u( "\uf100" ), |
045 | "angle-double-right" : u( "\uf101" ), |
046 | "angle-double-up" : u( "\uf102" ), |
047 | "angle-down" : u( "\uf107" ), |
048 | "angle-left" : u( "\uf104" ), |
049 | "angle-right" : u( "\uf105" ), |
050 | "angle-up" : u( "\uf106" ), |
051 | "apple" : u( "\uf179" ), |
052 | "archive" : u( "\uf187" ), |
053 | "arrow-circle-down" : u( "\uf0ab" ), |
054 | "arrow-circle-left" : u( "\uf0a8" ), |
055 | "arrow-circle-o-down" : u( "\uf01a" ), |
056 | "arrow-circle-o-left" : u( "\uf190" ), |
057 | "arrow-circle-o-right" : u( "\uf18e" ), |
058 | "arrow-circle-o-up" : u( "\uf01b" ), |
059 | "arrow-circle-right" : u( "\uf0a9" ), |
060 | "arrow-circle-up" : u( "\uf0aa" ), |
061 | "arrow-down" : u( "\uf063" ), |
062 | "arrow-left" : u( "\uf060" ), |
063 | "arrow-right" : u( "\uf061" ), |
064 | "arrow-up" : u( "\uf062" ), |
065 | "arrows" : u( "\uf047" ), |
066 | "arrows-alt" : u( "\uf0b2" ), |
067 | "arrows-h" : u( "\uf07e" ), |
068 | "arrows-v" : u( "\uf07d" ), |
069 | "asterisk" : u( "\uf069" ), |
070 | "automobile" : u( "\uf1b9" ), |
071 | "backward" : u( "\uf04a" ), |
074 | "bar-chart-o" : u( "\uf080" ), |
075 | "barcode" : u( "\uf02a" ), |
078 | "behance" : u( "\uf1b4" ), |
079 | "behance-square" : u( "\uf1b5" ), |
081 | "bell-o" : u( "\uf0a2" ), |
082 | "bitbucket" : u( "\uf171" ), |
083 | "bitbucket-square" : u( "\uf172" ), |
084 | "bitcoin" : u( "\uf15a" ), |
089 | "bookmark" : u( "\uf02e" ), |
090 | "bookmark-o" : u( "\uf097" ), |
091 | "briefcase" : u( "\uf0b1" ), |
094 | "building" : u( "\uf1ad" ), |
095 | "building-o" : u( "\uf0f7" ), |
096 | "bullhorn" : u( "\uf0a1" ), |
097 | "bullseye" : u( "\uf140" ), |
099 | "calendar" : u( "\uf073" ), |
100 | "calendar-o" : u( "\uf133" ), |
101 | "camera" : u( "\uf030" ), |
102 | "camera-retro" : u( "\uf083" ), |
104 | "caret-down" : u( "\uf0d7" ), |
105 | "caret-left" : u( "\uf0d9" ), |
106 | "caret-right" : u( "\uf0da" ), |
107 | "caret-square-o-down" : u( "\uf150" ), |
108 | "caret-square-o-left" : u( "\uf191" ), |
109 | "caret-square-o-right" : u( "\uf152" ), |
110 | "caret-square-o-up" : u( "\uf151" ), |
111 | "caret-up" : u( "\uf0d8" ), |
112 | "certificate" : u( "\uf0a3" ), |
113 | "chain" : u( "\uf0c1" ), |
114 | "chain-broken" : u( "\uf127" ), |
115 | "check" : u( "\uf00c" ), |
116 | "check-circle" : u( "\uf058" ), |
117 | "check-circle-o" : u( "\uf05d" ), |
118 | "check-square" : u( "\uf14a" ), |
119 | "check-square-o" : u( "\uf046" ), |
120 | "chevron-circle-down" : u( "\uf13a" ), |
121 | "chevron-circle-left" : u( "\uf137" ), |
122 | "chevron-circle-right" : u( "\uf138" ), |
123 | "chevron-circle-up" : u( "\uf139" ), |
124 | "chevron-down" : u( "\uf078" ), |
125 | "chevron-left" : u( "\uf053" ), |
126 | "chevron-right" : u( "\uf054" ), |
127 | "chevron-up" : u( "\uf077" ), |
128 | "child" : u( "\uf1ae" ), |
129 | "circle" : u( "\uf111" ), |
130 | "circle-o" : u( "\uf10c" ), |
131 | "circle-o-notch" : u( "\uf1ce" ), |
132 | "circle-thin" : u( "\uf1db" ), |
133 | "clipboard" : u( "\uf0ea" ), |
134 | "clock-o" : u( "\uf017" ), |
135 | "cloud" : u( "\uf0c2" ), |
136 | "cloud-download" : u( "\uf0ed" ), |
137 | "cloud-upload" : u( "\uf0ee" ), |
140 | "code-fork" : u( "\uf126" ), |
141 | "codepen" : u( "\uf1cb" ), |
142 | "coffee" : u( "\uf0f4" ), |
145 | "columns" : u( "\uf0db" ), |
146 | "comment" : u( "\uf075" ), |
147 | "comment-o" : u( "\uf0e5" ), |
148 | "comments" : u( "\uf086" ), |
149 | "comments-o" : u( "\uf0e6" ), |
150 | "compass" : u( "\uf14e" ), |
151 | "compress" : u( "\uf066" ), |
153 | "credit-card" : u( "\uf09d" ), |
155 | "crosshairs" : u( "\uf05b" ), |
158 | "cubes" : u( "\uf1b3" ), |
160 | "cutlery" : u( "\uf0f5" ), |
161 | "dashboard" : u( "\uf0e4" ), |
162 | "database" : u( "\uf1c0" ), |
163 | "dedent" : u( "\uf03b" ), |
164 | "delicious" : u( "\uf1a5" ), |
165 | "desktop" : u( "\uf108" ), |
166 | "deviantart" : u( "\uf1bd" ), |
168 | "dollar" : u( "\uf155" ), |
169 | "dot-circle-o" : u( "\uf192" ), |
170 | "download" : u( "\uf019" ), |
171 | "dribbble" : u( "\uf17d" ), |
172 | "dropbox" : u( "\uf16b" ), |
173 | "drupal" : u( "\uf1a9" ), |
175 | "eject" : u( "\uf052" ), |
176 | "ellipsis-h" : u( "\uf141" ), |
177 | "ellipsis-v" : u( "\uf142" ), |
178 | "empire" : u( "\uf1d1" ), |
179 | "envelope" : u( "\uf0e0" ), |
180 | "envelope-o" : u( "\uf003" ), |
181 | "envelope-square" : u( "\uf199" ), |
182 | "eraser" : u( "\uf12d" ), |
185 | "exchange" : u( "\uf0ec" ), |
186 | "exclamation" : u( "\uf12a" ), |
187 | "exclamation-circle" : u( "\uf06a" ), |
188 | "exclamation-triangle" : u( "\uf071" ), |
189 | "expand" : u( "\uf065" ), |
190 | "external-link" : u( "\uf08e" ), |
191 | "external-link-square" : u( "\uf14c" ), |
193 | "eye-slash" : u( "\uf070" ), |
194 | "facebook" : u( "\uf09a" ), |
195 | "facebook-square" : u( "\uf082" ), |
196 | "fast-backward" : u( "\uf049" ), |
197 | "fast-forward" : u( "\uf050" ), |
199 | "female" : u( "\uf182" ), |
200 | "fighter-jet" : u( "\uf0fb" ), |
202 | "file-archive-o" : u( "\uf1c6" ), |
203 | "file-audio-o" : u( "\uf1c7" ), |
204 | "file-code-o" : u( "\uf1c9" ), |
205 | "file-excel-o" : u( "\uf1c3" ), |
206 | "file-image-o" : u( "\uf1c5" ), |
207 | "file-movie-o" : u( "\uf1c8" ), |
208 | "file-o" : u( "\uf016" ), |
209 | "file-pdf-o" : u( "\uf1c1" ), |
210 | "file-photo-o" : u( "\uf1c5" ), |
211 | "file-picture-o" : u( "\uf1c5" ), |
212 | "file-powerpoint-o" : u( "\uf1c4" ), |
213 | "file-sound-o" : u( "\uf1c7" ), |
214 | "file-text" : u( "\uf15c" ), |
215 | "file-text-o" : u( "\uf0f6" ), |
216 | "file-video-o" : u( "\uf1c8" ), |
217 | "file-word-o" : u( "\uf1c2" ), |
218 | "file-zip-o" : u( "\uf1c6" ), |
219 | "files-o" : u( "\uf0c5" ), |
221 | "filter" : u( "\uf0b0" ), |
223 | "fire-extinguisher" : u( "\uf134" ), |
225 | "flag-checkered" : u( "\uf11e" ), |
226 | "flag-o" : u( "\uf11d" ), |
227 | "flash" : u( "\uf0e7" ), |
228 | "flask" : u( "\uf0c3" ), |
229 | "flickr" : u( "\uf16e" ), |
230 | "floppy-o" : u( "\uf0c7" ), |
231 | "folder" : u( "\uf07b" ), |
232 | "folder-o" : u( "\uf114" ), |
233 | "folder-open" : u( "\uf07c" ), |
234 | "folder-open-o" : u( "\uf115" ), |
236 | "forward" : u( "\uf04e" ), |
237 | "foursquare" : u( "\uf180" ), |
238 | "frown-o" : u( "\uf119" ), |
239 | "gamepad" : u( "\uf11b" ), |
240 | "gavel" : u( "\uf0e3" ), |
244 | "gears" : u( "\uf085" ), |
247 | "git-square" : u( "\uf1d2" ), |
248 | "github" : u( "\uf09b" ), |
249 | "github-alt" : u( "\uf113" ), |
250 | "github-square" : u( "\uf092" ), |
251 | "gittip" : u( "\uf184" ), |
252 | "glass" : u( "\uf000" ), |
253 | "globe" : u( "\uf0ac" ), |
254 | "google" : u( "\uf1a0" ), |
255 | "google-plus" : u( "\uf0d5" ), |
256 | "google-plus-square" : u( "\uf0d4" ), |
257 | "graduation-cap" : u( "\uf19d" ), |
258 | "group" : u( "\uf0c0" ), |
259 | "h-square" : u( "\uf0fd" ), |
260 | "hacker-news" : u( "\uf1d4" ), |
261 | "hand-o-down" : u( "\uf0a7" ), |
262 | "hand-o-left" : u( "\uf0a5" ), |
263 | "hand-o-right" : u( "\uf0a4" ), |
264 | "hand-o-up" : u( "\uf0a6" ), |
265 | "hdd-o" : u( "\uf0a0" ), |
266 | "header" : u( "\uf1dc" ), |
267 | "headphones" : u( "\uf025" ), |
268 | "heart" : u( "\uf004" ), |
269 | "heart-o" : u( "\uf08a" ), |
270 | "history" : u( "\uf1da" ), |
272 | "hospital-o" : u( "\uf0f8" ), |
273 | "html5" : u( "\uf13b" ), |
274 | "image" : u( "\uf03e" ), |
275 | "inbox" : u( "\uf01c" ), |
276 | "indent" : u( "\uf03c" ), |
278 | "info-circle" : u( "\uf05a" ), |
280 | "instagram" : u( "\uf16d" ), |
281 | "institution" : u( "\uf19c" ), |
282 | "italic" : u( "\uf033" ), |
283 | "joomla" : u( "\uf1aa" ), |
285 | "jsfiddle" : u( "\uf1cc" ), |
287 | "keyboard-o" : u( "\uf11c" ), |
289 | "language" : u( "\uf1ab" ), |
290 | "laptop" : u( "\uf109" ), |
292 | "legal" : u( "\uf0e3" ), |
293 | "lemon-o" : u( "\uf094" ), |
294 | "level-down" : u( "\uf149" ), |
295 | "level-up" : u( "\uf148" ), |
296 | "life-bouy" : u( "\uf1cd" ), |
297 | "life-ring" : u( "\uf1cd" ), |
298 | "life-saver" : u( "\uf1cd" ), |
299 | "lightbulb-o" : u( "\uf0eb" ), |
301 | "linkedin" : u( "\uf0e1" ), |
302 | "linkedin-square" : u( "\uf08c" ), |
303 | "linux" : u( "\uf17c" ), |
305 | "list-alt" : u( "\uf022" ), |
306 | "list-ol" : u( "\uf0cb" ), |
307 | "list-ul" : u( "\uf0ca" ), |
308 | "location-arrow" : u( "\uf124" ), |
310 | "long-arrow-down" : u( "\uf175" ), |
311 | "long-arrow-left" : u( "\uf177" ), |
312 | "long-arrow-right" : u( "\uf178" ), |
313 | "long-arrow-up" : u( "\uf176" ), |
314 | "magic" : u( "\uf0d0" ), |
315 | "magnet" : u( "\uf076" ), |
316 | "mail-forward" : u( "\uf064" ), |
317 | "mail-reply" : u( "\uf112" ), |
318 | "mail-reply-all" : u( "\uf122" ), |
320 | "map-marker" : u( "\uf041" ), |
321 | "maxcdn" : u( "\uf136" ), |
322 | "medkit" : u( "\uf0fa" ), |
323 | "meh-o" : u( "\uf11a" ), |
324 | "microphone" : u( "\uf130" ), |
325 | "microphone-slash" : u( "\uf131" ), |
326 | "minus" : u( "\uf068" ), |
327 | "minus-circle" : u( "\uf056" ), |
328 | "minus-square" : u( "\uf146" ), |
329 | "minus-square-o" : u( "\uf147" ), |
330 | "mobile" : u( "\uf10b" ), |
331 | "mobile-phone" : u( "\uf10b" ), |
332 | "money" : u( "\uf0d6" ), |
333 | "moon-o" : u( "\uf186" ), |
334 | "mortar-board" : u( "\uf19d" ), |
335 | "music" : u( "\uf001" ), |
336 | "navicon" : u( "\uf0c9" ), |
337 | "openid" : u( "\uf19b" ), |
338 | "outdent" : u( "\uf03b" ), |
339 | "pagelines" : u( "\uf18c" ), |
340 | "paper-plane" : u( "\uf1d8" ), |
341 | "paper-plane-o" : u( "\uf1d9" ), |
342 | "paperclip" : u( "\uf0c6" ), |
343 | "paragraph" : u( "\uf1dd" ), |
344 | "paste" : u( "\uf0ea" ), |
345 | "pause" : u( "\uf04c" ), |
347 | "pencil" : u( "\uf040" ), |
348 | "pencil-square" : u( "\uf14b" ), |
349 | "pencil-square-o" : u( "\uf044" ), |
350 | "phone" : u( "\uf095" ), |
351 | "phone-square" : u( "\uf098" ), |
352 | "photo" : u( "\uf03e" ), |
353 | "picture-o" : u( "\uf03e" ), |
354 | "pied-piper" : u( "\uf1a7" ), |
355 | "pied-piper-alt" : u( "\uf1a8" ), |
356 | "pied-piper-square" : u( "\uf1a7" ), |
357 | "pinterest" : u( "\uf0d2" ), |
358 | "pinterest-square" : u( "\uf0d3" ), |
359 | "plane" : u( "\uf072" ), |
361 | "play-circle" : u( "\uf144" ), |
362 | "play-circle-o" : u( "\uf01d" ), |
364 | "plus-circle" : u( "\uf055" ), |
365 | "plus-square" : u( "\uf0fe" ), |
366 | "plus-square-o" : u( "\uf196" ), |
367 | "power-off" : u( "\uf011" ), |
368 | "print" : u( "\uf02f" ), |
369 | "puzzle-piece" : u( "\uf12e" ), |
371 | "qrcode" : u( "\uf029" ), |
372 | "question" : u( "\uf128" ), |
373 | "question-circle" : u( "\uf059" ), |
374 | "quote-left" : u( "\uf10d" ), |
375 | "quote-right" : u( "\uf10e" ), |
377 | "random" : u( "\uf074" ), |
378 | "rebel" : u( "\uf1d0" ), |
379 | "recycle" : u( "\uf1b8" ), |
380 | "reddit" : u( "\uf1a1" ), |
381 | "reddit-square" : u( "\uf1a2" ), |
382 | "refresh" : u( "\uf021" ), |
383 | "renren" : u( "\uf18b" ), |
384 | "reorder" : u( "\uf0c9" ), |
385 | "repeat" : u( "\uf01e" ), |
386 | "reply" : u( "\uf112" ), |
387 | "reply-all" : u( "\uf122" ), |
388 | "retweet" : u( "\uf079" ), |
391 | "rocket" : u( "\uf135" ), |
392 | "rotate-left" : u( "\uf0e2" ), |
393 | "rotate-right" : u( "\uf01e" ), |
394 | "rouble" : u( "\uf158" ), |
396 | "rss-square" : u( "\uf143" ), |
398 | "ruble" : u( "\uf158" ), |
399 | "rupee" : u( "\uf156" ), |
401 | "scissors" : u( "\uf0c4" ), |
402 | "search" : u( "\uf002" ), |
403 | "search-minus" : u( "\uf010" ), |
404 | "search-plus" : u( "\uf00e" ), |
406 | "send-o" : u( "\uf1d9" ), |
407 | "share" : u( "\uf064" ), |
408 | "share-alt" : u( "\uf1e0" ), |
409 | "share-alt-square" : u( "\uf1e1" ), |
410 | "share-square" : u( "\uf14d" ), |
411 | "share-square-o" : u( "\uf045" ), |
412 | "shield" : u( "\uf132" ), |
413 | "shopping-cart" : u( "\uf07a" ), |
414 | "sign-in" : u( "\uf090" ), |
415 | "sign-out" : u( "\uf08b" ), |
416 | "signal" : u( "\uf012" ), |
417 | "sitemap" : u( "\uf0e8" ), |
418 | "skype" : u( "\uf17e" ), |
419 | "slack" : u( "\uf198" ), |
420 | "sliders" : u( "\uf1de" ), |
421 | "smile-o" : u( "\uf118" ), |
423 | "sort-alpha-asc" : u( "\uf15d" ), |
424 | "sort-alpha-desc" : u( "\uf15e" ), |
425 | "sort-amount-asc" : u( "\uf160" ), |
426 | "sort-amount-desc" : u( "\uf161" ), |
427 | "sort-asc" : u( "\uf0de" ), |
428 | "sort-desc" : u( "\uf0dd" ), |
429 | "sort-down" : u( "\uf0dd" ), |
430 | "sort-numeric-asc" : u( "\uf162" ), |
431 | "sort-numeric-desc" : u( "\uf163" ), |
432 | "sort-up" : u( "\uf0de" ), |
433 | "soundcloud" : u( "\uf1be" ), |
434 | "space-shuttle" : u( "\uf197" ), |
435 | "spinner" : u( "\uf110" ), |
436 | "spoon" : u( "\uf1b1" ), |
437 | "spotify" : u( "\uf1bc" ), |
438 | "square" : u( "\uf0c8" ), |
439 | "square-o" : u( "\uf096" ), |
440 | "stack-exchange" : u( "\uf18d" ), |
441 | "stack-overflow" : u( "\uf16c" ), |
443 | "star-half" : u( "\uf089" ), |
444 | "star-half-empty" : u( "\uf123" ), |
445 | "star-half-full" : u( "\uf123" ), |
446 | "star-half-o" : u( "\uf123" ), |
447 | "star-o" : u( "\uf006" ), |
448 | "steam" : u( "\uf1b6" ), |
449 | "steam-square" : u( "\uf1b7" ), |
450 | "step-backward" : u( "\uf048" ), |
451 | "step-forward" : u( "\uf051" ), |
452 | "stethoscope" : u( "\uf0f1" ), |
454 | "strikethrough" : u( "\uf0cc" ), |
455 | "stumbleupon" : u( "\uf1a4" ), |
456 | "stumbleupon-circle" : u( "\uf1a3" ), |
457 | "subscript" : u( "\uf12c" ), |
458 | "suitcase" : u( "\uf0f2" ), |
459 | "sun-o" : u( "\uf185" ), |
460 | "superscript" : u( "\uf12b" ), |
461 | "support" : u( "\uf1cd" ), |
462 | "table" : u( "\uf0ce" ), |
463 | "tablet" : u( "\uf10a" ), |
464 | "tachometer" : u( "\uf0e4" ), |
467 | "tasks" : u( "\uf0ae" ), |
469 | "tencent-weibo" : u( "\uf1d5" ), |
470 | "terminal" : u( "\uf120" ), |
471 | "text-height" : u( "\uf034" ), |
472 | "text-width" : u( "\uf035" ), |
474 | "th-large" : u( "\uf009" ), |
475 | "th-list" : u( "\uf00b" ), |
476 | "thumb-tack" : u( "\uf08d" ), |
477 | "thumbs-down" : u( "\uf165" ), |
478 | "thumbs-o-down" : u( "\uf088" ), |
479 | "thumbs-o-up" : u( "\uf087" ), |
480 | "thumbs-up" : u( "\uf164" ), |
481 | "ticket" : u( "\uf145" ), |
482 | "times" : u( "\uf00d" ), |
483 | "times-circle" : u( "\uf057" ), |
484 | "times-circle-o" : u( "\uf05c" ), |
486 | "toggle-down" : u( "\uf150" ), |
487 | "toggle-left" : u( "\uf191" ), |
488 | "toggle-right" : u( "\uf152" ), |
489 | "toggle-up" : u( "\uf151" ), |
490 | "trash-o" : u( "\uf014" ), |
492 | "trello" : u( "\uf181" ), |
493 | "trophy" : u( "\uf091" ), |
494 | "truck" : u( "\uf0d1" ), |
496 | "tumblr" : u( "\uf173" ), |
497 | "tumblr-square" : u( "\uf174" ), |
498 | "turkish-lira" : u( "\uf195" ), |
499 | "twitter" : u( "\uf099" ), |
500 | "twitter-square" : u( "\uf081" ), |
501 | "umbrella" : u( "\uf0e9" ), |
502 | "underline" : u( "\uf0cd" ), |
504 | "university" : u( "\uf19c" ), |
505 | "unlink" : u( "\uf127" ), |
506 | "unlock" : u( "\uf09c" ), |
507 | "unlock-alt" : u( "\uf13e" ), |
508 | "unsorted" : u( "\uf0dc" ), |
509 | "upload" : u( "\uf093" ), |
512 | "user-md" : u( "\uf0f0" ), |
513 | "users" : u( "\uf0c0" ), |
514 | "video-camera" : u( "\uf03d" ), |
515 | "vimeo-square" : u( "\uf194" ), |
518 | "volume-down" : u( "\uf027" ), |
519 | "volume-off" : u( "\uf026" ), |
520 | "volume-up" : u( "\uf028" ), |
521 | "warning" : u( "\uf071" ), |
522 | "wechat" : u( "\uf1d7" ), |
523 | "weibo" : u( "\uf18a" ), |
524 | "weixin" : u( "\uf1d7" ), |
525 | "wheelchair" : u( "\uf193" ), |
526 | "windows" : u( "\uf17a" ), |
528 | "wordpress" : u( "\uf19a" ), |
529 | "wrench" : u( "\uf0ad" ), |
531 | "xing-square" : u( "\uf169" ), |
532 | "yahoo" : u( "\uf19e" ), |
534 | "youtube" : u( "\uf167" ), |
535 | "youtube-play" : u( "\uf16a" ), |
536 | "youtube-square" : u( "\uf166" ), |
540 | class ListAction(argparse.Action): |
541 | def __call__( self , parser, namespace, values, option_string = None ): |
542 | for icon in sorted (icons.keys()): |
547 | class ListUpdateAction(argparse.Action): |
548 | def __call__( self , parser, namespace, values, option_string = None ): |
550 | for icon in sorted (icons.keys()): |
551 | print (u ' "%s": u("\\u%x"),' % (icon, ord (icons[icon]))) |
556 | def export_icon(icon, size, filename, font, color): |
557 | image = Image.new( "RGBA" , (size, size), color = ( 0 , 0 , 0 , 0 )) |
559 | draw = ImageDraw.Draw(image) |
562 | font = ImageFont.truetype(font, size) |
565 | width,height = draw.textsize(icons[icon], font = font) |
567 | draw.text(((size - width) / 2 , (size - height) / 2 ), icons[icon], |
568 | font = font, fill = color) |
571 | bbox = image.getbbox() |
574 | imagemask = Image.new( "L" , (size, size), 0 ) |
575 | drawmask = ImageDraw.Draw(imagemask) |
578 | drawmask.text(((size - width) / 2 , (size - height) / 2 ), icons[icon], |
582 | iconimage = Image.new( "RGBA" , (size,size), color) |
583 | iconimage.putalpha(imagemask) |
586 | iconimage = iconimage.crop(bbox) |
588 | borderw = int ((size - (bbox[ 2 ] - bbox[ 0 ])) / 2 ) |
589 | borderh = int ((size - (bbox[ 3 ] - bbox[ 1 ])) / 2 ) |
592 | outimage = Image.new( "RGBA" , (size, size), ( 0 , 0 , 0 , 0 )) |
593 | outimage.paste(iconimage, (borderw,borderh)) |
596 | outimage.save(filename) |
599 | class LoadCSSAction(argparse.Action): |
600 | def __call__( self , parser, namespace, values, option_string = None ): |
602 | icons = LoadCSSAction._load_css(values) |
605 | def _load_css(filename): |
608 | parser = tinycss.make_parser( "page3" ) |
611 | stylesheet = parser.parse_stylesheet_file(filename) |
613 | print >> sys.stderr, ( "Error: CSS file (%s) can't be opened" |
617 | is_icon = re. compile (u( "\.fa-(.*):before,?" )) |
618 | for rule in stylesheet.rules: |
619 | selector = rule.selector.as_css() |
620 | for match in is_icon.finditer(selector): |
621 | name = match.groups()[ 0 ] |
622 | for declaration in rule.declarations: |
623 | if declaration.name = = u "content" : |
624 | val = declaration.value.as_css() |
627 | new_icons[name] = uchr( int (val[ 1 :], 16 )) |
631 | if __name__ = = '__main__' : |
632 | parser = argparse.ArgumentParser( |
633 | description = "Exports Font Awesome icons as PNG images." ) |
635 | parser.add_argument( "icon" , type = str , nargs = "+" , |
636 | help = "The name(s) of the icon(s) to export (or \"ALL\" for all icons)" ) |
637 | parser.add_argument( "--color" , type = str , default = "black" , |
638 | help = "Color (HTML color code or name, default: black)" ) |
639 | parser.add_argument( "--filename" , type = str , |
640 | help = "The name of the output file (it must end with \".png\"). If " + |
641 | "all files are exported, it is used as a prefix." ) |
642 | parser.add_argument( "--font" , type = str , default = "fontawesome-webfont.ttf" , |
643 | help = "Font file to use (default: fontawesome-webfont.ttf)" ) |
644 | parser.add_argument( "--css" , type = str , default = "", action = LoadCSSAction, |
645 | help = "Path to the CSS file defining icon names (instead of the " + |
647 | parser.add_argument( "--list" , nargs = 0 , action = ListAction, |
648 | help = "List available icon names and exit" ) |
649 | parser.add_argument( "--list-update" , nargs = 0 , action = ListUpdateAction, |
650 | help = argparse.SUPPRESS) |
651 | parser.add_argument( "--size" , type = int , default = 16 , |
652 | help = "Icon size in pixels (default: 16)" ) |
654 | args = parser.parse_args() |
661 | if not path.isfile(args.font) or not access(args.font, R_OK): |
662 | print >> sys.stderr, ( "Error: Font file (%s) can't be opened" |
666 | if args.icon = = [ "ALL" ]: |
668 | selected_icons = sorted (icons.keys()) |
673 | for icon in args.icon: |
675 | if icon.startswith( "icon-" ): |
679 | selected_icons.append(icon) |
681 | print >> sys.stderr, "Error: Unknown icon name (%s)" % (icon) |
684 | for icon in selected_icons: |
685 | if len (selected_icons) > 1 : |
687 | filename = (args.filename or " ") + icon + " .png" |
691 | filename = args.filename |
693 | filename = icon + ".png" |
695 | print ( "Exporting icon \"%s\" as %s (%ix%i pixels)" % |
696 | (icon, filename, size, size)) |
698 | export_icon(icon, size, filename, font, color) |
帮助文档 README.md:
04 | This program allows you to extract the awesome |
10 | font-awesome-to-png.py [-h] [--color COLOR] [--filename FILENAME] |
11 | [--font FONT] [--css CSS] [--list] [--size SIZE] |
15 | icon The name(s) of the icon(s) to export (or "ALL" for |
19 | --color COLOR Color (HTML color code or name, default : black) |
20 | --filename FILENAME The name of the output file (it must end with |
21 | ".png" ). If all files are exported, it is used as a |
23 | --font FONT Font file to use ( default : fontawesome-webfont.ttf) |
24 | --css CSS Path to the CSS file defining icon names (instead of |
26 | --list List available icon names and exit |
27 | --size SIZE Icon size in pixels ( default : 16) |
29 | hidden optional arguments: |
30 | --list-update List available icon names and codes in format suitable |
31 | for updating the program source. |
33 | To use the program, you need the Font Awesome TTF file, which is available in |
34 | [Font Awesome Github repository] (https: |
36 | The internal icon list is matched to Font Awesome 4.1.0. To use a later/different |
37 | version, use font-awesome.css from the Font Awesome GitHub repository. |
41 | Export the "play" and "stop" icons as 24x24 pixels images: |
43 | font-awesome-to-png.py --size 24 play stop |
45 | Export the asterisk icon as 32x32 pixels image, in blue: |
47 | font-awesome-to-png.py --size 32 --color blue asterisk |
49 | Export all icons as 16x16 pixels images: |
51 | font-awesome-to-png.py ALL |