#!/bin/sh # This script tested with bash 5.1, zsh 5.8, ksh 93u, and dash 0.5.11.4. # If your environment doesn't have a shell compatible with one of those, # I can't help you. SELF="$(basename $0)" # allow overriding magick path via environment. MAGICK=${MAGICK:-magick} # only change this if the save file size changes in dla.xex. SIZE="256x170" usage() { cat < [dla-file] is a file created by the Save option in dla.xex. [image-file] is the output file: any image file that ImageMagick knows how to create. Image type is determined by filename extension, e.g. "filename.png" or "filename.bmp". Try "magick -list format|less" to see the the full list. If any arguments after the [image-file] are present, they will be passed to the magick executable as-is. The most useful argument here is probably -trim, which will automatically crop the black borders around the image. See the ImageMagick documentation for the full list of supported arguments. See also: https://slackware.uk/~urchlay/repos/dla-asm EOF } INFILE="$1" OUTFILE="$2" if [ -z "$INFILE" -o -z "$OUTFILE" -o "$INFILE" = "-h" -o "$INFILE" = "--help" ]; then usage exit 0 fi shift 2 # do the conversion... if $OUTFILE has an unknown extension, we will # not get an error, and the conversion will succeed (the output will # just be a copy of the input!) $MAGICK convert -size "$SIZE" -depth 1 "$@" gray:"$INFILE" "$OUTFILE" # if magick fails, exit with its error status (it already printed its # error messages to stderr). S="$?" if [ "$S" != "0" ]; then exit "$S" fi # if magick "succeeds" but the output is identical to the input, let # the user know. if cmp "$INFILE" "$OUTFILE" >/dev/null 2>&1; then rm -f "$OUTFILE" echo "$SELF: Unsupported filename extension; see ImageMagick docs." 1>&2 exit 1 fi exit 0