Skip to main content

A command line interface tool to generate pride flags from images.

Project description

pyflagoras

🏳️‍🌈 A Python command line interface tool for generating pride flags from images. The program accepts any image 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 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.

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] [--verbose] [--svg] [--version] [-l] image

A command line interface tool for generating pride flags from 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.
                        Examples:
                            intersexinclusive
                            nonbinary
                        Default:
                            progresspride
  -n NAME, --name NAME  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)
                            {F}: Flag ID (e.g progressPride_2018)
                        Examples:
                            pyflagoras celeste_classic.png -n "{f}_{n}" [renders Progress Pride_celeste_classic.png]       
                        Default:
                            {n}_{F} [renders celeste_classic_progressPride_2018.png]

  --verbose             Enable verbosity (for general info and debugging)
  --svg                 Generate the flag's .svg file in addition to the .png
  --version             show the program's version number and exit
  -l, --list            show all flag aliases and exit

Documentation, issues and more: https://github.com/phthallo/pyflagoras

Tip: Using --verbose will log the coordinates of where the colours were found on your image!

Development

Substitute py for python3 as necessary.

  1. Clone the repository.
    git clone https://github.com/phthallo/pyflagoras
    
  2. Install the build tool.
    py -m pip install --upgrade build
    
  3. cd to the root of the repository and build the package.
    py -m build
    
  4. 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 /dist subdirectory. You can then install the wheel using:
    py -m pip install dist/pyflagoras-x.x.x-py3-none-any.whl
    

Contributions

The current pride flags have been sourced from @/JoeHart's Pride Flag API.

To add a new flag, see addingflags.md.

Notes

  • The name pyflagoras comes 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyflagoras-0.3.4.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

pyflagoras-0.3.4-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file pyflagoras-0.3.4.tar.gz.

File metadata

  • Download URL: pyflagoras-0.3.4.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for pyflagoras-0.3.4.tar.gz
Algorithm Hash digest
SHA256 e1a27d35a35c7421ee4ceded481e27c333eb77a1566f7b2f298245e1fa8c4c1f
MD5 2dc38735d63a90f19c16799470c19d41
BLAKE2b-256 ff241b13f8298b150c1c854d0dcee37f498cb0c743844ba81c8540cf29275627

See more details on using hashes here.

File details

Details for the file pyflagoras-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: pyflagoras-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for pyflagoras-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 19b6e4da4f7a8774cd64886419329db99603ae028a67a35ade222cf710583d5e
MD5 e4cb17571ac17f3479a50f40c13fbf51
BLAKE2b-256 dd85a2c8495cba39bc18def4345d32f32af9bf3091c4616a383e3d94ad509eac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page