pyflagoras
🏳️🌈 A Python command line interface tool for theming .svg files using user-provided images. The program accepts any image file, an .svg file and outputs the flag as a .png file.
https://github.com/phthallo/pyflagoras/assets/84078890/8927779e-5e1c-411e-9d14-6bf1bdb8396d
(To see more examples of flags generated using this program, visit examples.md!)
How does it work?
Pyflagoras, at a minimum, needs the name of a pride flag, or a path to an .svg, and a path to an image to work.
It uses Pillow to generate a list of colours in the image.
The program then obtains the flag's .svg file from the alias used, and extracts the all the colours used in the flag. It uses an algorithm to calculate which colours are the most similar based on their RGB codes.
Finally, the colours are swapped out. The .svg is converted into a .pdf using svglib then into a .png using PyMuPDF.
tl;dr - if you ever wanted the Slack logo to have the same colours as a cool photo you took you absolutely can.
Installation
You can install this package from pypi.org! Open a terminal and run the following:
pip install pyflagoras
Usage
$ pyflagoras --help
usage: pyflagoras [-h] [-f FLAG] [-n NAME] [-a {low_cost,pythagoras,cielab}] [--verbose] [--svg]
[--highlight] [--version] [-l]
image
A command line interface tool for theming .svg files using user-provided images.
positional arguments:
image Path to the image to generate a flag from.
Examples:
image.png
foo/bar/image.jpg
options:
-h, --help show this help message and exit
-f FLAG, --flag FLAG The alias of the flag to generate OR path to a custom .svg file.
Examples:
intersexinclusive
/foo/bar/file.svg
Default:
progresspride
-o OUTPUT, --output OUTPUT
Customise the name of the final .png. The following can be used as part of the file name:
Format placeholders:
{n}: File name (e.g celeste_classic)
{N}: File name (full) (e.g celeste_classic.png)
{f}: Flag name (e.g Progress Pride) [N/A for custom .svg]
{F}: Flag ID (e.g progressPride_2018) [N/A for custom .svg]
Examples:
pyflagoras celeste_classic.png -n "{f}_{n}" [renders Progress Pride_celeste_classic.png]
Default:
{n}_{F} [renders celeste_classic_progressPride_2018.png]
-a {low_cost,pythagoras,cielab}, --algorithm {low_cost,pythagoras,cielab}
Change the algorithm used to determine colour similarity.
--verbose Enable verbosity (for general info and debugging)
--svg Generate the flag's .svg file in addition to the .png
--highlight Generate an image to highlight where the similar colours were found.
--version show the program's version number and exit
-l, --list show all flag aliases and exit
Tip:
Development
Substitute py for python3 as necessary.
- Clone the repository.
git clone https://github.com/phthallo/pyflagoras - Install the build tool.
py -m pip install --upgrade build cdto the root of the repository and build the package.py -m build- Both the source distribution (
pyflagoras-x.x.x-tar.gz) and the built distribution (pyflagoras-x.x.x-py3-none-any.whl) will be found under the/distsubdirectory. You can then install the wheel using:py -m pip install dist/pyflagoras-x.x.x-py3-none-any.whl
- To preview your changes without having to build, run the following to install Pyflagoras in editable mode.
py -m pip install -e .
Contributions
The current 'pre-loaded' .svg files are pride flags! They have been sourced from @/JoeHart's Pride Flag API.
To add a new flag, see addingflags.md.
Notes
- The name
pyflagorascomes from python, pride flag, and the basic colour similarity algorithm being a 3D application of Pythagoras' theorem. - See also the prideflagbot account (gone but not forgotten!) run by @/michalpazur, which was a big inspiration for this project.
Metadata
Release files for pyflagoras 0.5.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyflagoras-0.5.4.tar.gz | 21.7 kB | Without provenance | Details for pyflagoras-0.5.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyflagoras-0.5.4-py3-none-any.whl | Python 3 | none | any | Details for pyflagoras-0.5.4-py3-none-any.whl |
Total release size: 52.2 kB
Release files / pyflagoras-0.5.4.tar.gz
| Download URL | pyflagoras-0.5.4.tar.gz |
|---|---|
| Size | 21.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e35b3dedaf5e7b2de057c7d8925fa3ba008972f70d06ea6247cad1ba912b027
|
|
BLAKE2b-256 checksum How to use checksums |
921024b5ef72739fab201c91c6f7db3a44ca02c8f60442273456b5ab5040c084
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Release files / pyflagoras-0.5.4-py3-none-any.whl
| Download URL | pyflagoras-0.5.4-py3-none-any.whl |
|---|---|
| Size | 30.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7506f1ccb669f2343df0c2018dacd85243fa1264a5d5e3e5b757a650cda30759
|
|
BLAKE2b-256 checksum How to use checksums |
2112c6b9ea89c2c6a74ec60e5bc8773ba6bc28f213682eda233cc9b4421140a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Security for pyflagoras 0.5.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.