Skip to content

Instantly share code, notes, and snippets.

@Winterhuman
Winterhuman / sisyphus.sh
Last active March 4, 2025 22:20
A script for finding the smallest lossless encoding of a PNG or GIF input image (that I know of).
#!/usr/bin/env -S unshare --pid --mount-proc --kill-child --map-root-user /bin/sh
# Licensed under the Zero-Clause BSD terms: https://opensource.org/license/0bsd
## Requires pngquant, oxipng, gifsicle, gif2apng, and optionally libwebp &
## perl-image-exiftool
## -C: Fail if redirects try to overwrite an existing file.
## -e: Fail if any command fails (with exceptions).
## -u: Fail if an unset variable tries to be expanded.
@Winterhuman
Winterhuman / Results.txt
Last active September 26, 2023 04:22
Strange OxiPNG-PNGQuant results
# Explanation
PNGQuant: `pngquant --quality 100-100 --speed 1 --strip`
OxiPNG: `oxipng --opt max --strip all --alpha`
OxiPNG-ZF: `oxipng --opt max --strip all --alpha --zopfli`
Oxi-Quant: "PNGQuant" > "OxiPNG" (non-ZF)
@Winterhuman
Winterhuman / ppm2png.sh
Last active April 27, 2025 15:48
A script which finds the minimum PNG dimensions for a given aspect ratio and pixel count, creates a colour-cycling PPM file, and then converts it to PNG.
#!/usr/bin/env -S unshare --mount --map-root-user /bin/sh
# Licensed under the Zero-Clause BSD terms: https://opensource.org/license/0bsd
# Requires: imagemagick & [sisyphus](https://gist.github.com/Winterhuman/21d7b148db40ff041f397b07a7aafb83)
#
# Argument 1: Number of pixels to fill, required
# Argument 2: Height ratio, default 23
# Argument 3: Width ratio, default 5
set -Ceuf
@Winterhuman
Winterhuman / avif.sh
Last active May 11, 2025 07:10
POSIX sh script to create AVIF for a target SSIM score using binary search, requires `imagemagick` and `cavif`.
#!/usr/bin/env -S unshare --mount --map-root-user /bin/sh
# Licensed under the Zero-Clause BSD terms: https://opensource.org/license/0bsd
## Requires `imagemagick` and `cavif`
## -C: Fail if redirects try to overwrite an existing file.
## -e: Fail if any command fails (with exceptions).
## -u: Fail if an unset variable tries to be expanded.
## -f: No glob expansion.