💾 Archived View for laniakea.rodoste.de › journal › 2023-05-24-dither.gmi captured on 2023-05-24 at 17:42:09. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2023-06-14)

-=-=-=-=-=-=-

🏠 home

dithering photos

2023-05-24

I made a short z-shell script to apply dithering to input pictures.

The whole thing started when Skyjake on geminispace.org pointed me to the low-tech magazine the other day. The low-tech magazine operates a solar powered server to host a version of the magazine, fully willing to let it go offline when there is a longer spell of bad weather. One of the many things they do to preserve energy is to convert their pictures to four gray values, dither it for more pleasant looks and apply a tint.

What I do in my script is inspired by, but different to their final results. I started out to see for myself how big the file size difference actually is but then thought I might one day turn this into something useful.

As chance would have it, today there's a request for such a script on geminispace.

So here it goes, my humble first version of the script. It doesn't check for anything and it requires `convert` from the ImageMagick suite.

#!/usr/bin/env zsh

doTint=1

pastels=("#FEDDB2" "#F0ADDC" "#A47DCA" "#9EC8F3" "#C4F0C2")
color="#ffffff"

if [ $doTint -eq 1 ]; then
  n=$((1 + $RANDOM % $#pastels))
  color=$pastels[n]
fi

# convert center-crop image, dither it to 8 colors and tint with identified color
convert $1 \
  -gravity center -crop 2:1 \
  -resize 800x400 \
  -colorspace gray -fill $color -tint 100 \
  -dither FloydSteinberg -colors 8 \
  - 

It will print the raw image data to stdout so to use, call it like this:

dither.zsh path/to/image.jpg > output.jpg

or pipe it into an image previewer

dither.zsh path/to/image.jpg | feh -

----

𝕃𝕚𝕟𝕜𝕤

geminispace.org

the solar-powered low-tech magazine

the convert script from the ImageMagick suite

a color palette generator

----

see all my articles