Coder Social home page Coder Social logo

pythonity / icon-font-to-png Goto Github PK

View Code? Open in Web Editor NEW
207.0 207.0 32.0 307 KB

Python script (and library) for exporting icons from icon fonts (e.g. Font Awesome, Octicons) as PNG images

Home Page: https://pythonity.github.io/icon-font-to-png/

License: MIT License

CSS 0.45% Python 99.55%
command-line-tool font-awesome icon-font octicons python

icon-font-to-png's People

Contributors

mluedke2 avatar odyniec avatar pawelad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

icon-font-to-png's Issues

ValueError: unichr() arg not in range(0x10000) (narrow Python build)

python: 2.7.10 (the macOS builtin Python)
os: macOS 10.11.5
here is my iconfont.css file
iconfont.css.txt

โžœ  ux_1473385914_8062558 icon-font-to-png --css iconfont.css --ttf iconfont.ttf --size 128
Traceback (most recent call last):
  File "/usr/local/bin/icon-font-to-png", line 16, in <module>
    command_line.run(sys.argv[1:])
  File "/Library/Python/2.7/site-packages/icon_font_to_png/command_line.py", line 97, in run
    keep_prefix=args.keep_prefix)
  File "/Library/Python/2.7/site-packages/icon_font_to_png/icon_font.py", line 24, in __init__
    self.css_icons, self.common_prefix = self.load_css()
  File "/Library/Python/2.7/site-packages/icon_font_to_png/icon_font.py", line 62, in load_css
    icons[name] = unichr(int(val[1:], 16))
ValueError: unichr() arg not in range(0x10000) (narrow Python build)

How-to query for Windows

Hello,
python and github novice here, so pardon me if this is out of order here.

on windows with anaconda, how does one run the following example:
icon-font-to-png --css font-awesome.css --ttf fontawesome-webfont.ttf --list

above has a shell prompt, so i presume is for linux

what i have done on windows are as follows:

  • pip install icon_font_to_png (on anaconda cmdline, success)
  • icon-font-to-png --css font-awesome.css --ttf fontawesome-webfont.ttf --list (on anaconda cmdline, failed: 'icon-font-to-png' is not recognized ...)
  • icon-font-to-png --css font-awesome.css --ttf fontawesome-webfont.ttf --list (on windows cmdline at C:\Users\user\Anaconda3\Scripts>, failed: 'icon-font-to-png' is not recognized ...)

Kindly advise please. TIA

Error downloading font awesome using command example

Running the first example I get the error urllib.error.HTTPError: HTTP Error 404: Not Found.

On OSX 10.15.2 and Python 3.5.6:

(env) nathan@Nathans-MBP fontawesometopng % icon-font-to-png --download font-awesome
Traceback (most recent call last):

File "/Users/nathan/Playground/fontawesometopng/env/bin/icon-font-to-png", line 16, in
command_line.run(sys.argv[1:])
File "/Users/nathan/Playground/fontawesometopng/env/lib/python3.5/site-packages/icon_font_to_png/command_line.py", line 85, in run
downloader = download_icon_font(args.download, os.getcwd())
File "/Users/nathan/Playground/fontawesometopng/env/lib/python3.5/site-packages/icon_font_to_png/command_line.py", line 172, in download_icon_font
downloader.download_files()
File "/Users/nathan/Playground/fontawesometopng/env/lib/python3.5/site-packages/icon_font_to_png/icon_font_downloader.py", line 75, in download_files
self.css_path = self.download_css(self.directory)
File "/Users/nathan/Playground/fontawesometopng/env/lib/python3.5/site-packages/icon_font_to_png/icon_font_downloader.py", line 67, in download_css
return self._download_file_from_url(self.css_url, directory)
File "/Users/nathan/Playground/fontawesometopng/env/lib/python3.5/site-packages/icon_font_to_png/icon_font_downloader.py", line 49, in _download_file_from_url
return urlretrieve(url, filename=css_filename)[0]
File "/Users/nathan/.pyenv/versions/3.5.6/lib/python3.5/urllib/request.py", line 188, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/Users/nathan/.pyenv/versions/3.5.6/lib/python3.5/urllib/request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "/Users/nathan/.pyenv/versions/3.5.6/lib/python3.5/urllib/request.py", line 472, in open
response = meth(req, response)
File "/Users/nathan/.pyenv/versions/3.5.6/lib/python3.5/urllib/request.py", line 582, in http_response
'http', request, response, code, msg, hdrs)
File "/Users/nathan/.pyenv/versions/3.5.6/lib/python3.5/urllib/request.py", line 510, in error
return self._call_chain(*args)
File "/Users/nathan/.pyenv/versions/3.5.6/lib/python3.5/urllib/request.py", line 444, in _call_chain
result = func(*args)
File "/Users/nathan/.pyenv/versions/3.5.6/lib/python3.5/urllib/request.py", line 590, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

--color Hex value support?

๐Ÿ‘ Very nice and most useful utility...

I try --color with hex value, but I got error, icon-font-to-png would support custom colorize by hex values.

TypeError on Mac OS X 10.10 using python 2.7

I've tried

Mac OS X 10.10.2 (Yosemite)

Traceback (most recent call last):
  File "/usr/local/bin/icon-font-to-png", line 8, in <module>
    from icon_font_to_png import command_line
  File "/Library/Python/2.7/site-packages/icon_font_to_png/__init__.py", line 2, in <module>
    from .icon_font_downloader import (
  File "/Library/Python/2.7/site-packages/icon_font_to_png/icon_font_downloader.py", line 15, in <module>
    class IconFontDownloader(object, with_metaclass(ABCMeta)):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/abc.py", line 87, in __new__
    cls = super(ABCMeta, mcls).__new__(mcls, name, bases, namespace)
TypeError: Error when calling the metaclass bases
    Cannot create a consistent method resolution
order (MRO) for bases NewBase, object

The following is the output of installing icon-font-to-png (and dependencies) using pip:

Downloading/unpacking icon-font-to-png
  Downloading icon_font_to_png-0.3.2-py2.py3-none-any.whl
Downloading/unpacking tinycss>=0.3 (from icon-font-to-png)
  Downloading tinycss-0.3.tar.gz (72kB): 72kB downloaded
  Running setup.py (path:/private/tmp/pip_build_root/tinycss/setup.py) egg_info for package tinycss
    Building without Cython.

    no previously-included directories found matching 'docs/_build'
Downloading/unpacking requests>=2.9.1 (from icon-font-to-png)
  Downloading requests-2.9.1-py2.py3-none-any.whl (501kB): 501kB downloaded
Downloading/unpacking pillow>=3.0.0 (from icon-font-to-png)
  Downloading Pillow-3.1.1-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (2.9MB): 2.9MB downloaded
Downloading/unpacking six>=1.10.0 (from icon-font-to-png)
  Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: icon-font-to-png, tinycss, requests, pillow, six
  Running setup.py install for tinycss
    Building without Cython.
    building 'tinycss.speedups' extension
    cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c tinycss/speedups.c -o build/temp.macosx-10.10-intel-2.7/tinycss/speedups.o
    tinycss/speedups.c:705:14: warning: explicitly assigning value of variable of type 'PyObject *' (aka 'struct _object *') to itself [-Wself-assign]
      __pyx_self = __pyx_self;
      ~~~~~~~~~~ ^ ~~~~~~~~~~
    tinycss/speedups.c:1571:14: warning: explicitly assigning value of variable of type 'PyObject *' (aka 'struct _object *') to itself [-Wself-assign]
      __pyx_self = __pyx_self;
      ~~~~~~~~~~ ^ ~~~~~~~~~~
    tinycss/speedups.c:5348:33: warning: unused function '__Pyx_PyInt_FromSize_t' [-Wunused-function]
    static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
                                    ^
    tinycss/speedups.c:5362:29: warning: unused function '__Pyx_PyInt_AsSize_t' [-Wunused-function]
    static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
                                ^
    tinycss/speedups.c:469:32: warning: unused function '__Pyx_GetItemInt_Tuple_Fast' [-Wunused-function]
    static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
                                   ^
    tinycss/speedups.c:509:26: warning: unused function '__Pyx_NegateNonNeg' [-Wunused-function]
    static CYTHON_INLINE int __Pyx_NegateNonNeg(int b) {
                             ^
    tinycss/speedups.c:512:32: warning: unused function '__Pyx_PyBoolOrNull_FromLong' [-Wunused-function]
    static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
                                   ^
    tinycss/speedups.c:4481:36: warning: unused function '__Pyx_PyInt_AsUnsignedChar' [-Wunused-function]
    static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
                                       ^
    tinycss/speedups.c:4500:37: warning: unused function '__Pyx_PyInt_AsUnsignedShort' [-Wunused-function]
    static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
                                        ^
    tinycss/speedups.c:4519:35: warning: unused function '__Pyx_PyInt_AsUnsignedInt' [-Wunused-function]
    static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
                                      ^
    tinycss/speedups.c:4538:27: warning: unused function '__Pyx_PyInt_AsChar' [-Wunused-function]
    static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
                              ^
    tinycss/speedups.c:4557:28: warning: unused function '__Pyx_PyInt_AsShort' [-Wunused-function]
    static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
                               ^
    tinycss/speedups.c:4595:34: warning: unused function '__Pyx_PyInt_AsSignedChar' [-Wunused-function]
    static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
                                     ^
    tinycss/speedups.c:4614:35: warning: unused function '__Pyx_PyInt_AsSignedShort' [-Wunused-function]
    static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
                                      ^
    tinycss/speedups.c:4633:33: warning: unused function '__Pyx_PyInt_AsSignedInt' [-Wunused-function]
    static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
                                    ^
    tinycss/speedups.c:4652:26: warning: unused function '__Pyx_PyInt_AsLongDouble' [-Wunused-function]
    static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
                             ^
    tinycss/speedups.c:4776:35: warning: function '__Pyx_PyInt_AsLongLong' is not needed and will not be emitted [-Wunneeded-internal-declaration]
    static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
                                      ^
    tinycss/speedups.c:4846:42: warning: function '__Pyx_PyInt_AsSignedLongLong' is not needed and will not be emitted [-Wunneeded-internal-declaration]
    static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
                                             ^
    tinycss/speedups.c:4896:27: warning: unused function '__Pyx_ErrFetch' [-Wunused-function]
    static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
                              ^
    19 warnings generated.
    tinycss/speedups.c:705:14: warning: explicitly assigning value of variable of type 'PyObject *' (aka 'struct _object *') to itself [-Wself-assign]
      __pyx_self = __pyx_self;
      ~~~~~~~~~~ ^ ~~~~~~~~~~
    tinycss/speedups.c:1571:14: warning: explicitly assigning value of variable of type 'PyObject *' (aka 'struct _object *') to itself [-Wself-assign]
      __pyx_self = __pyx_self;
      ~~~~~~~~~~ ^ ~~~~~~~~~~
    tinycss/speedups.c:5348:33: warning: unused function '__Pyx_PyInt_FromSize_t' [-Wunused-function]
    static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
                                    ^
    tinycss/speedups.c:5362:29: warning: unused function '__Pyx_PyInt_AsSize_t' [-Wunused-function]
    static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
                                ^
    tinycss/speedups.c:469:32: warning: unused function '__Pyx_GetItemInt_Tuple_Fast' [-Wunused-function]
    static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
                                   ^
    tinycss/speedups.c:509:26: warning: unused function '__Pyx_NegateNonNeg' [-Wunused-function]
    static CYTHON_INLINE int __Pyx_NegateNonNeg(int b) {
                             ^
    tinycss/speedups.c:512:32: warning: unused function '__Pyx_PyBoolOrNull_FromLong' [-Wunused-function]
    static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
                                   ^
    tinycss/speedups.c:4481:36: warning: unused function '__Pyx_PyInt_AsUnsignedChar' [-Wunused-function]
    static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
                                       ^
    tinycss/speedups.c:4500:37: warning: unused function '__Pyx_PyInt_AsUnsignedShort' [-Wunused-function]
    static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
                                        ^
    tinycss/speedups.c:4519:35: warning: unused function '__Pyx_PyInt_AsUnsignedInt' [-Wunused-function]
    static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
                                      ^
    tinycss/speedups.c:4538:27: warning: unused function '__Pyx_PyInt_AsChar' [-Wunused-function]
    static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
                              ^
    tinycss/speedups.c:4557:28: warning: unused function '__Pyx_PyInt_AsShort' [-Wunused-function]
    static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
                               ^
    tinycss/speedups.c:4595:34: warning: unused function '__Pyx_PyInt_AsSignedChar' [-Wunused-function]
    static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
                                     ^
    tinycss/speedups.c:4614:35: warning: unused function '__Pyx_PyInt_AsSignedShort' [-Wunused-function]
    static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
                                      ^
    tinycss/speedups.c:4633:33: warning: unused function '__Pyx_PyInt_AsSignedInt' [-Wunused-function]
    static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
                                    ^
    tinycss/speedups.c:4652:26: warning: unused function '__Pyx_PyInt_AsLongDouble' [-Wunused-function]
    static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
                             ^
    tinycss/speedups.c:4776:35: warning: function '__Pyx_PyInt_AsLongLong' is not needed and will not be emitted [-Wunneeded-internal-declaration]
    static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
                                      ^
    tinycss/speedups.c:4846:42: warning: function '__Pyx_PyInt_AsSignedLongLong' is not needed and will not be emitted [-Wunneeded-internal-declaration]
    static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
                                             ^
    tinycss/speedups.c:4896:27: warning: unused function '__Pyx_ErrFetch' [-Wunused-function]
    static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
                              ^
    19 warnings generated.
    cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.10-intel-2.7/tinycss/speedups.o -o build/lib.macosx-10.10-intel-2.7/tinycss/speedups.so

    no previously-included directories found matching 'docs/_build'
Successfully installed icon-font-to-png tinycss requests pillow six
Cleaning up...

I've been able to successfully install and run icon-font-to-png on a linux machine however and it appears the issue might be related to the install of pillow. I'm not too familiar with pip and I might be posting this in the wrong repository, if so, please let me know!

NoneType error on bbox

Hi,

Trying to workaround FontAwesome awkwardness, i hit a bug with bounding box management. Here is the output:

$ icon-font-to-png --css my-font-awesome.css --ttf my-fontawesome-webfont.ttf ALL
Exporting icon '500px' as '500px.png'(16x16 pixels)
Traceback (most recent call last):
  File "/home/bersace/.local/share/virtualenvs/pandocker/bin/icon-font-to-png", line 16, in <module>
    command_line.run(sys.argv[1:])
  File "/home/bersace/.local/share/virtualenvs/pandocker/lib/python3.5/site-packages/icon_font_to_png/command_line.py", line 161, in run
    color=args.color, scale=args.scale)
  File "/home/bersace/.local/share/virtualenvs/pandocker/lib/python3.5/site-packages/icon_font_to_png/icon_font.py", line 155, in export_icon
    border_w = int((size - (bbox[2] - bbox[0])) / 2)
TypeError: 'NoneType' object is not subscriptable
52             if bbox:                                                         
153                 icon_image = icon_image.crop(bbox)
154                                                                        
155  ->         border_w = int((size - (bbox[2] - bbox[0])) / 2)
156             border_h = int((size - (bbox[3] - bbox[1])) / 2)
157                                
158             # Create output image
159             out_image = Image.new("RGBA", (size, size), (0, 0, 0, 0))
160             out_image.paste(icon_image, (border_w, border_h))

I don't understand why there is an if bbox as if bbox can be None, but border_* lines requires bbox to be defined. Can you give me a clue ? I can send you a patch.

KeyError in PIL with Keyrune

When I try to convert all Icons from https://github.com/andrewgioia/Keyrune I get a KeyError because it tries to convert an icon and save it as '.png' without prefix.
The list seems to contain an empty name as first element. I don't know anything about icon fonts, so I can't tell who is wrong here. Maybe allow the tool to ignore these errors and just tell the user that it couldn't convert it?
Thanks for the tool btw :)

Loading .css

Can't get this to work ... not sure what kind of CSS file to provide.
I tried
node_modules/@fortawesome/fontawesome-svg-core/styles.css
But --list showed nothing.

Thanks!

List available icons using --list fails

I am using the current version, installed via pip.

Downloading the font using:

icon-font-to-png --download font-awesome

worked without issues - as a result i got the .css and the .ttf file.

But if i try to list all icons using:

icon-font-to-png --css font-awesome.css --ttf fontawesome-webfont.ttf --list

i get no output at all.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.