Skip to content

Instantly share code, notes, and snippets.

@themactep
Created May 9, 2023 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themactep/75e58479f7e761f7b10cfafbc5542895 to your computer and use it in GitHub Desktop.
Save themactep/75e58479f7e761f7b10cfafbc5542895 to your computer and use it in GitHub Desktop.
thumbnailer for .stl files
#!/bin/bash
# .STL files thumbnailer
# 2022, Paul Philippov, paul@themactep.com
set -euo pipefail
OS=$(command -v openscad || command -v openscad-nightly)
IFS=$'\n\t'
FOO=$(basename "$1")
TMPFILE="/tmp/stl2png_$FOO.scad"
echo "import(\"$1\");" > "$TMPFILE"
$OS -o "$2.png" -D "\$fn=128" --autocenter --viewall \
--colorscheme="Cornfield" -q "$TMPFILE"
rm "$TMPFILE"
mogrify -fuzz "1%" -transparent "#ffffe5" -trim +repage -resize "$3x$3>" \
-gravity center -background transparent -extent "$3x$3" "$2.png"
mv "$2.png" "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment