💾 Archived View for laniakea.rodoste.de › journal › 2023-05-24-dither.gmi captured on 2023-11-14 at 07:43:31. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-11-04)

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

🏠 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
    doGrayscale=0 
    
    pastels=("#FEDDB2" "#F0ADDC" "#A47DCA" "#9EC8F3" "#C4F0C2")
    color="#ffffff"
    
    if [ $doTint -eq 1 ]; then
      n=$((1 + $RANDOM % $#pastels))
      color=$pastels[n]
      doGrayscale=1
    fi
    
    if [ $doGrayscale -eq 1 ]; then
      # 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 - 
    
    else
      convert $1 \
        -gravity center -crop 2:1 \
        -resize 800x400 \
        -dither FloydSteinberg -colors 8 -
    fi 

It generates output images in the reduced colorspace of the original, plain grayscale or tinted.

Output looks like this:

Earth, in the original colorspace

Earth, in grayscale

Earth, tint variation 1

Earth, tint variation 2

Earth, tint variation 3

Earth, tint variation 3

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 -

Links

geminispace.org

the solar-powered low-tech magazine

the convert script from the ImageMagick suite

a color palette generator

---

see all my articles