Tirsvad ccc1eee93d
TirSystem/git-workflows: Release / release (push) Skipped
TirSystem/git-workflows: Publish accepted milestones / publish (push) Skipped
TirSystem/git-workflows: Publish wiki / publish-wiki (push) Successful in 22s
TirSystem/git-workflows: OpenGrep / opengrep (push) Successful in 46s
TirSystem/git-workflows: Validate / validate (push) Successful in 18s
TirSystem/git-workflows: Sync GitHub mirror metadata / sync-metadata (push) Successful in 6s
Merge pull request 'Release: wiki, reflection and publication' (#6) from milestone/mil-006-release into main
Reviewed-on: #6
2026-11-21 03:57:17 +01:00
2026-11-21 10:36:54 +08:00
2026-11-21 10:26:35 +08:00
2026-11-21 02:27:00 +01:00
2026-11-21 10:26:33 +08:00
2026-11-21 10:36:54 +08:00

🚀 Image Colour Palette Generator

A small website where you upload an image and see its top 10 most common colours with their HEX codes, counted with NumPy. Day 92 assignment of the 100 Days of Code Python course.

📚 Table of Contents

🧭 Overview

Open the page, choose an image and press Find colours. The page shows the image beside ten swatches, most common first, each with its HEX code and its share of the image. Click a swatch to copy its HEX code.

How the colours are counted:

  1. Pillow decodes the upload and scales it down to at most 300 px on the long side, which keeps the proportions of the colours and makes counting fast.
  2. NumPy reshapes the image to a list of RGBA pixels and drops the transparent ones (alpha below 128).
  3. Each channel is grouped into buckets (24 wide by default, 1 to 64), so near-identical shades in a photo count as one colour. Set the grouping to 1 to count exact colours.
  4. np.unique(..., axis=0, return_counts=True) counts each colour, and np.argsort picks the ten most common.

The web server uses only the Python standard library (http.server), so the only runtime dependencies are NumPy and Pillow.

Folder What it holds
src/colour_palette/domain/ Colour counting with NumPy (find_top_colours) and the ColourShare value
src/colour_palette/application/ The use case: PaletteService.build_palette
src/colour_palette/infrastructure/ Image decoding with Pillow (PillowImageReader)
src/colour_palette/presentation/ The web server, the form parser and the HTML page
src/colour_palette/constants.py Every constant: number of colours, bucket size, upload limit, host and port
tests/unit/, tests/integration/ pytest tests; the integration tests run the server on 127.0.0.1
docs/ Project documents; docs/images/ holds the screenshots
docs/use-cases/uc-001-get-colour-palette/ The use case and its design: DM, SSD, OC, SD and DCD
docs/adr/ Architecture decisions: standard library web server, downscale and quantise

The table shows the finished layout: step 2 adds the package, constants.py and a smoke test, step 4 the domain, application and infrastructure layers, and step 5 the presentation layer.

📋 Requirements

Requirement Why
Python 3.14 or newer The language the project is written in
NumPy Counts the colours (the point of the assignment)
Pillow Reads PNG, JPEG, GIF, BMP and WebP uploads
pytest (development only) Runs the tests
Doxygen (optional) Builds the API documentation from the source comments

🛠️ Setup

Create a local virtual environment in .venv, upgrade pip, and install the project with its test tools.

Linux and macOS:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

Windows (PowerShell):

py -3.14 -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

To install only what the app needs to run, use python -m pip install -e .. Leave the environment with deactivate. The .venv folder is in .gitignore.

▶️ Run

With the virtual environment active:

python -m colour_palette

Open http://127.0.0.1:8000 in a browser. Stop the server with Ctrl+C. Use --port 8080 for another port, or --host 0.0.0.0 to reach it from other machines on your network. colour-palette is a shortcut for the same command.

Uploads are limited to 10 MB and are never stored; the image is read in memory and dropped after the page is sent. The server is Python's http.server, meant for local use, not for the open internet (ADR-0001).

🧪 Tests

python -m pytest

With coverage: python -m pytest --cov=colour_palette.

The tests build their images in memory, read no files and use no network besides the loopback server started by the integration tests.

Build the API documentation (optional): run doxygen in the repository root and open docs/doxygen/html/index.html.

🪜 Steps

The project is built in steps, one branch and pull request each. The wiki has a page per step that explains what was learned, in English, Danish and Bahasa Melayu, and a reflection journal.

Step Milestone What it adds Screenshot Wiki
1 MIL-001 Baseline Business case, stakeholders, project plan and milestones 01-baseline.png Step 1
2 MIL-002 Scaffold pyproject.toml, constants.py, smoke test, .gitignore, .editorconfig, Doxyfile, this README 02-scaffold-tests.png Step 2
3 MIL-003 Design Use case UC-001, ADR-0001 and ADR-0002, domain model, system sequence diagram, operation contract, sequence diagram and design class diagram 03-design-use-case.png Step 3
4 MIL-004 Engine Pillow image reader, NumPy colour counting (find_top_colours), PaletteService and their unit tests 04-engine-tests.png Step 4
5 MIL-005 Website Upload form, result page with swatches and HEX codes, error pages, web tests 05-website-top-ten-colours.png Step 5

Step 1, the Project Plan with its six milestones:

Step 1: Project Plan

Step 2, the smoke tests passing in the .venv:

Step 2: Smoke tests

Step 3, the use case UC-001:

Step 3: Use case UC-001

Step 4, the engine tests with full coverage:

Step 4: Engine tests

Step 5, the website. The upload page:

Upload page

The top 10 colours of the sample image (docs/images/sample-sunset.png):

Top 10 colours

📄 License

GNU Affero General Public License v3.0 or later, see LICENSE.

📎 Appendix: Project documents

Document What it tells you
AGENTS.md The rules agents follow in this repository
Business Case Why the project exists, its scope and success criteria
Stakeholder Analysis Who is involved; the stakeholder IDs used for owners and reviewers
Project Plan The gateways and their schedule
Milestones One document per gateway: Go/No-Go criteria and tasks
Use case UC-001 The user goal and its design diagrams
Design Class Diagram The classes and layers of the code
Artifact registry Where each artifact type lives, the next version, the PO language and domain
Framework README The framework this project uses
Framework changelog What changed in each framework release

S
Description
A website that finds the top 10 most common colours in an uploaded image, with NumPy. Day 92 of 100 Days of Code.
Readme AGPL-3.0
3.1 MiB
0 Stars 1 Watchers 0 Forks
Languages
Python 100%