Skip to main content

Python script to generate a 128x128 image from the unique hash of a file

Project description

icon-gen

Generates a deterministic 128x128 PNG icon from any file. The icon is a color grid where each square's RGB value is derived from the SHAKE-256 hash of the input file — the same file always produces the same icon.

Installation

uv sync

Usage

uv run icon-gen <filepath> [options]

Arguments

Argument Description
filepath Path to the file to generate an icon for

Options

Option Default Description
-s, --squares 64 Number of squares in the grid. Must be one of: 1, 4, 16, 64
-n, --name icon.png Output filename. Must end in .png
-d, --dry-run off Preview the image without saving it

Examples

# Generate icon for a file with default settings (64 squares, saved as icon.png)
uv run icon-gen myfile.bin

# 4x4 grid saved to a custom filename
uv run icon-gen myfile.bin --squares 16 --name myfile-icon.png

# Preview without saving
uv run icon-gen myfile.bin --dry-run

How it works

  1. The input file is hashed using SHAKE-256, producing 192 bytes of output
  2. The 128x128 image is divided into a square grid of --squares cells
  3. Each cell is filled with an RGB color taken from 3 consecutive bytes of the hash (1 byte per channel)
  4. The grid reads left-to-right, top-to-bottom

With 64 squares and 3 bytes per square, all 192 hash bytes are consumed exactly once — every square gets a unique RGB value.

Edge cases

  • --squares must be a power of 4 (1, 4, 16, 64). Other values are rejected.
  • Output filename must end in .png. Passing a non-.png name raises an error before any work is done.
  • --dry-run opens a system image viewer and does not write any file. The output of --name is ignored in dry-run mode.
  • The input file must exist and be readable. If it cannot be opened, the help text is printed and the process exits.
  • Icons are deterministic: the same file always produces the same icon regardless of when or where the command is run.

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

icon_from_file-0.1.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

icon_from_file-0.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file icon_from_file-0.1.0.tar.gz.

File metadata

  • Download URL: icon_from_file-0.1.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for icon_from_file-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bb503afb34e5d4314371c5795d496f25eb94de10911f81e3e4f31dc4ab21bf31
MD5 ce1e52d9a6d6d645659b6448e317dc2e
BLAKE2b-256 c538cece1a85cab4e8ee1070ae020113fce72de8f9377a31f02824ed181a9365

See more details on using hashes here.

Provenance

The following attestation bundles were made for icon_from_file-0.1.0.tar.gz:

Publisher: release.yml on emnul/IconGen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file icon_from_file-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: icon_from_file-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for icon_from_file-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0987b46116affcc34364baeba74dbdefd8446822d59b90a0c120ff8bb93d1c1
MD5 9f88a8868167ad73dbbe6a22ff33f429
BLAKE2b-256 0963befcc5cd7a4d5278fa80c74d27fdf62025b471a147a780ecf893dac857f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for icon_from_file-0.1.0-py3-none-any.whl:

Publisher: release.yml on emnul/IconGen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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