Skip to content

Instantly share code, notes, and snippets.

@Winterhuman
Winterhuman / sisyphus.sh
Last active December 10, 2024 16:51
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() { rm -r "$tmp" || pquit "Failed to delete '$tmp'!\n"; }
@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 December 10, 2024 16:47
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 --map-root-user --mount /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
pstat() {
@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),