Skip to content

Instantly share code, notes, and snippets.

@Winterhuman
Winterhuman / sisyphus.sh
Last active October 23, 2023 22:28
A script for finding the smallest lossless encoding of a PNG or GIF input image (that I know of).
#!/bin/sh
# Licensed under the Zero-Clause BSD terms: https://opensource.org/license/0bsd
# Requires pngquant, oxipng, gifsicle, gif2apng, libwebp, and optionally perl-image-exiftool.
perr() { printf "\033[1m\033[31m%b\033[0;39m" "$1"; }
pquit() { perr "$1"; exit 1; }
pstat() { printf "\033[1m\033[34m%b\033[0;39m\033[1m%b\033[0;39m\n" "$1" "$2"; }
clean() { if ! rm -r "$tmp"; then pquit "Failed to delete '$tmp'!\n"; fi }
@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 September 18, 2023 16:36
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.
#!/bin/sh
# Licensed under the Zero-Clause BSD terms: https://opensource.org/license/0bsd
# Requires imagemagick, and optionally pngquant & optipng
#
# Argument 1: Number of pixels to fill, required.
# Argument 2: Height ratio, default 23.
# Argument 3: Width ratio, default 5.
pquit() { printf "\033[1m\033[31m%b\033[0;39m" "$1"; exit 1; }
@Winterhuman
Winterhuman / avif.sh
Last active October 27, 2023 16:52
POSIX sh script to create AVIF for target SSIM value using binary search, requires `imagemagick` and `cavif`.
#!/bin/sh
# Licensed under the Zero-Clause BSD terms: https://opensource.org/license/0bsd
# Requires `imagemagick` and `cavif`.
## Arguments
# 1: /path/to/input
# 2: /path/to/output (optional, default output: 'input_no_ext'-'quality'.avif)
# 3: Target SSIM value (default value: 96%)
# Since the SSIM score is output as a 6 decimal place number (e.g. 0.960000),