Code Poster generates an SVG image from a source image using text taken from code files in a github repository.
This project is inspired by the Elixir project by Pete Corey. Pete did much of the hard work like determining the optimal image size and how to adjust the image to correct for the font width. Read his post here and see the elixir code here.
This version automatically scales the image by a configured ratio so that any image can be used without modification.
Download and unzip the latest release of the Adobe fonts.
- Open
Font Book
- Select
File -> Add Fonts
- Navigate to the unzipped directory, open the
TFF
directory, and select all theSourceCodePro-*.tff
files.
The following commands will create a virtual envrionment, activate it, and install the project's requirements.
virtualenv venv
source venv/bin/activate
pip install -r requirements
The configuration file defines the options for retrieving the source code from GitHub and SVG options.
YOU MUST copy the config.yml.EXAMPLE
file to config.yml
before running the application.
github:
api_url: https://api.github.com
username: <OPTIONAL>
personal_access_token: <OPTIONAL>
owner: unitedstates
repo: congress-legislators
branch: master
code_file_regex: '^.*\.(scala|js|py|cs|java)$'
Option | Description |
---|---|
api_url | The GitHub API URL. Can be changed to use Github Enterprise API v3 |
username | The username to make GitHub API calls as. This is REQUIRED if using public GitHub, optional if using GitHub Enterprise. Remove from config file if not used. |
personal_access_token | The personal access token to make GitHub API calls with. This is REQUIRED if using public GitHub, optional if using GitHub Enterprise. Remove from config file if not used. |
owner | The owner of the repository to use |
repo | The name of the repo to use |
branch | The branch of code to use |
code_file_regex | The regular expression used to determine which files in GitHub to use for the source code. By default the expression scans .scala, .js, .py, .cs, and .java files. |
svg:
font_family: 'Source Code Pro'
font_size: 1
ratio: 0.6
Option | Description |
---|---|
font_family | The font to use to generate the SVG |
font_size | The size of the font |
ratio | The amount of compensation to make with widths because the font is not exactly 1 pixel wide. Adjust with caution |
Before running make sure you have the following:
- A source image to use
- A GitHub repository configured in the
config.yml
file.
Run the following command:
python svg.py -i logo.png -o code.svg
The GitHub example will download a version of the GitHub logo and create an SVG using the code in the platform-samples repository.
To run the Github example do the following:
- Copy
examples/github/config.yml.EXAMPLE
toconfig.yml
- Update the
[github]
section with the appropriate username and personal_access_token - Run the command
./examples/github/run.sh