TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/1TSnakers/ProgressiveImageLoader/llms.txt
Use this file to discover all available pages before exploring further.
image_ruiner.py companion script automates the creation of progressively lower-quality PNG variants from a single source image. It works by repeatedly resizing the image downward using nearest-neighbour interpolation to produce a pixelation effect, then saving each step as a numbered PNG file. After all variants are generated, it writes an image_list.js file containing a JavaScript array of the output paths in the order that ProgressiveImageLoader expects — most degraded first, original quality last.
Requirements
- Python 3 — the script uses f-strings and
pathlib-style operations available in Python 3.6+. - Pillow — the
PILimage processing library must be installed before running the script. - A TTF font file — the default label font is
GoogleSansCode-Regular.ttf, which is included in theimages/directory of the repository. You can substitute any.ttffile by passing its path to thefont_fileparameter.
Function Signature
Parameters
Path to the source image that will be degraded. The path should be relative to the
images/ directory (the working directory from which the script is run). Supported formats are any image type that Pillow can open — PNG and JPEG work reliably.Directory (relative to the
images/ working directory) into which the generated PNG files will be saved. The directory is created automatically if it does not exist.The number of degradation steps to generate. The script produces
steps + 1 total images — one for each step plus the least-degraded (closest to original) variant. With the default of 8, you get 9 images: degraded_000.png through degraded_100.png at roughly equal quality intervals.Base font size (in points) for the quality-percentage label drawn in the bottom-left corner of each image. The actual rendered size scales dynamically with the output image dimensions so the label remains legible even on highly degraded (small) variants. This parameter has no effect when
show_label=False.Path to the TrueType font (
.ttf) file used to render the label overlay. The path is resolved relative to the images/ working directory. The repository ships with GoogleSansCode-Regular.ttf, so no extra download is needed when using the default.If the specified font file cannot be found or loaded, the script does not abort — it prints a warning and falls back to Pillow’s built-in default bitmap font. The default font is very small and may look poor on high-resolution images, so it’s best to keep the TTF file in place.
Text prepended to the percentage value in the label overlay. The full label rendered on each image is the prefix followed by the degradation percentage (for example
Quality reduced by: 50%). Change this to suit your preferred wording or to localise the output. This parameter has no effect when show_label=False.Controls whether the quality-percentage label is drawn on each output image. Set to
False to produce clean output images without any text overlay — useful when the degraded images will be displayed directly to end users rather than used for debugging.Output
After a successful run, the script produces:-
PNG files inside
output_dir, named using a zero-padded three-digit quality percentage:degraded_000.png(most pixelated / lowest quality) throughdegraded_100.png(least degraded, closest to the source). With the default ofsteps=8, the filenames produced are: -
image_list.js— written to theimages/working directory. It exports a default JavaScript array with the image paths in the orderProgressiveImageLoaderrequires (most degraded first):Import this file directly into your HTML page’s module script and pass it as theimagesoption toProgressiveImageLoader.
Running the Script
Install Pillow
Install the required Python image library using pip. Python 3 must already be installed on your system.
Place your source image and font file
Copy your source image (e.g.
sample.png) and the GoogleSansCode-Regular.ttf font file into the images/ directory. The font file is already present if you cloned the repository — you only need to add your own image.Run the script from the images/ directory
Change into the On success, the terminal prints the number of images saved and the absolute path of the output directory:
images/ directory and execute the script with Python. The working directory must be images/ so that relative paths for the font file and output resolve correctly.Usage Example
The following call matches the__main__ block at the bottom of image_ruiner.py and represents the standard invocation used in the project demo:
images/pixel_degraded_pngs/ and writes images/image_list.js.
GitHub Actions Integration
The repository includes a workflow at.github/workflows/run-image-ruiner.yml that runs image_ruiner.py automatically and commits the generated PNG files and image_list.js back to the repository. This means you can update your source image, push to main or master, and have the full degraded image set regenerated without running anything locally.
The workflow triggers on:
workflow_dispatch also allows you to trigger the workflow manually from the GitHub Actions UI without making a commit. After the script runs, the workflow stages and commits the generated assets: