Skip to content

Commit

Permalink
Major restructuration of the script
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelad committed Nov 26, 2015
1 parent 3a70711 commit 5ae4844
Show file tree
Hide file tree
Showing 50 changed files with 3,307 additions and 594 deletions.
90 changes: 90 additions & 0 deletions .gitignore
@@ -0,0 +1,90 @@
# Created by https://www.gitignore.io/api/python,pycharm

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/


### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio

*.iml

## Directory-based project format:
.idea/

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
11 changes: 11 additions & 0 deletions .travis.yml
@@ -0,0 +1,11 @@
language: python

install:
- pip install tox --use-mirrors

script:
- tox

env:
- TOXENV=py27
- TOXENV=py34
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Sidnet Solutions Sp. z o.o.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,14 @@
include *.md
include *.py
include *.txt
include LICENSE
include tests
include tox.ini
recursive-include icon_font_to_png *.css
recursive-include icon_font_to_png *.py
recursive-include icon_font_to_png *.ttf
recursive-include requirements *.txt
recursive-include tests *.css
recursive-include tests *.png
recursive-include tests *.py
recursive-include tests *.ttf
119 changes: 85 additions & 34 deletions README.md
@@ -1,34 +1,85 @@
Icon Font to PNG
================

This program allows you to extract icons from an icon font (e.g. Font Awesome or
Octicons) as PNG images of specified size.

### Usage

icon_font_to_png.py [-h] [--color COLOR] [--filename FILENAME]
[--keep-prefix] [--scale SCALE] [--size SIZE]
[--list]
ttf-file css-file [icon [icon ...]]

positional arguments:
ttf-file the name of the TTF file
css-file the name of the CSS file

optional arguments:
-h, --help show this help message and exit

exporting icons:
icon the name(s) of the icon(s) to export (or "ALL" for all
icons)
--color COLOR color (HTML color code or name, default: black)
--filename FILENAME the name of the output file, ending with ".png" (if
multiple icons are exported, the value of this option
is used as a prefix)
--keep-prefix do not remove common icon prefix
--scale SCALE scale (a scaling factor between 0 and 1, or "auto" for
automatic scaling, default: 1)
--size SIZE icon size in pixels (default: 16)

listing icon names:
--list list available icon names and exit
# Icon Font to PNG
Python (2 & 3 compatible) script for exporting icons from icon font
(e.g. Font Awesome, Octicons) as PNG images. It also comes with
`font-awesome-to-png` script for backward compatibility.

Packages required for running and testing are listed in
`requirements` directory.

Feel free to use, ask, fork, report bugs, fix them, suggest enhancements
and point out any mistakes.

## Installation
With `pip` (recommended):
```
$ pip install icon_font_to_png
```

Without `pip`:
```
$ git clone https://github.com/Pythonity/icon-font-to-png
$ pip install -r icon-font-to-png/requirements.txt
$ cd icon-font-to-png/bin
```

## Usage
```
usage: icon-font-to-png [-h] [--list] [--download {font-awesome,octicons}]
[--ttf TTF-FILE] [--css CSS-FILE] [--size SIZE]
[--scale SCALE] [--color COLOR] [--filename FILENAME]
[--keep_prefix]
[icons [icons ...]]
Exports font icons as PNG images.
optional arguments:
-h, --help show this help message and exit
--list list all available icon names and exit
--download {font-awesome,octicons}
download latest icon font and exit
required arguments:
--ttf TTF-FILE path to TTF file
--css CSS-FILE path to CSS file
exporting icons:
icons names of the icons to export (or 'ALL' for all icons)
--size SIZE icon size in pixels (default: 16)
--scale SCALE scaling factor between 0 and 1, or 'auto' for
automatic scaling (default: auto); be careful, as
setting it may lead to icons being cropped
--color COLOR HTML color code or name (default: black)
--filename FILENAME name of the output file (without '.png' extension);
it's used as a prefix if multiple icons are exported
--keep_prefix do not remove common icon prefix (i.e. 'fa-arrow-
right' instead of 'arrow-right')
```

## Examples
Download latest Font Awesome:
`$ icon-font-to-png --download font-awesome`

List all available icons:
`$ icon-font-to-png --css font-awesome.css --ttf fontawesome-webfont.ttf --list`

Export 'play' and 'stop' icons, size 64x64:
`$ icon-font-to-png --css font-awesome.css --ttf fontawesome-webfont.ttf --size 64 play stop`

Export all icons in blue:
`$ icon-font-to-png --css font-awesome.css --ttf fontawesome-webfont.ttf --color blue ALL`

Or alternatively you can use `font_awesome_to_png.py`
and skip `--css` and `--ttf` parameters (everything else works the same):
`$ font-awesome-to-png ALL`

## Tests
Package was tested with `tox` on Python 2.7 and Python 3.4 (see `tox.ini`).

To run tests yourself, just run `tox` inside repository.

## Authors
Developed and maintained by [Pythonity](http://pythonity.com/)

Originally version by [Michał Wojciechowski](https://github.com/odyniec),
refactored by [Paweł Adamczak](https://github.com/pawelad)
29 changes: 29 additions & 0 deletions bin/font-awesome-to-png
@@ -0,0 +1,29 @@
#!/usr/bin/env python

import os
import sys

try:
# Installed system wide
from icon_font_to_png import command_line
except ImportError:
# Locally
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from icon_font_to_png import command_line


if __name__ == '__main__':
# TODO: Download only once, and load after?
# Download Font Awesome to temp directory
font_awesome = command_line.download_icon_font('font-awesome',
directory=None)

# Append paths to Font Awesome files
args = sys.argv[1:]
args.append('--css')
args.append(font_awesome.css_path)
args.append('--ttf')
args.append(font_awesome.ttf_path)

# Execute original script
command_line.run(args)
16 changes: 16 additions & 0 deletions bin/icon-font-to-png
@@ -0,0 +1,16 @@
#!/usr/bin/env python

import os
import sys

try:
# Installed system wide
from icon_font_to_png import command_line
except ImportError:
# Locally
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from icon_font_to_png import command_line


if __name__ == '__main__':
command_line.run(sys.argv[1:])

0 comments on commit 5ae4844

Please sign in to comment.