75 lines
1.5 KiB
Bash
Executable File
75 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Default values
|
|
INVERT=false
|
|
|
|
# Help function
|
|
usage() {
|
|
echo "Usage: $0 [-i] <tape_width_mm> <input_image.png>"
|
|
echo "Options:"
|
|
echo " -i Invert colors (Black -> White, White -> Black)"
|
|
echo "Example: $0 -i 12 sticker.png"
|
|
exit 1
|
|
}
|
|
|
|
# Parse options
|
|
while getopts "i" opt; do
|
|
case $opt in
|
|
i) INVERT=true ;;
|
|
*) usage ;;
|
|
esac
|
|
done
|
|
shift $((OPTIND-1))
|
|
|
|
# Check for remaining arguments
|
|
if [ "$#" -ne 2 ]; then
|
|
usage
|
|
fi
|
|
|
|
TAPE_WIDTH=$1
|
|
INPUT_FILE=$2
|
|
|
|
# Map tape width (mm) to pixel height
|
|
case $TAPE_WIDTH in
|
|
3.5) PIXELS=24 ;;
|
|
6) PIXELS=32 ;;
|
|
9) PIXELS=48 ;;
|
|
12) PIXELS=64 ;;
|
|
18) PIXELS=96 ;;
|
|
24) PIXELS=128 ;;
|
|
36) PIXELS=192 ;;
|
|
*)
|
|
echo "Error: Unsupported tape width ($TAPE_WIDTH mm)."
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
if [ ! -f "$INPUT_FILE" ]; then
|
|
echo "Error: File $INPUT_FILE not found."
|
|
exit 1
|
|
fi
|
|
|
|
FILENAME=$(basename -- "$INPUT_FILE")
|
|
EXTENSION="${FILENAME##*.}"
|
|
BASENAME="${FILENAME%.*}"
|
|
|
|
# Prepare the magick command parts
|
|
INVERT_CMD=""
|
|
if [ "$INVERT" = true ]; then
|
|
INVERT_CMD="-negate"
|
|
echo "Color inversion: ENABLED"
|
|
fi
|
|
|
|
echo "Processing $INPUT_FILE for ${TAPE_WIDTH}mm tape (${PIXELS}px slices)..."
|
|
|
|
# Execute ImageMagick
|
|
magick "$INPUT_FILE" \
|
|
$INVERT_CMD \
|
|
-threshold 50% \
|
|
-type Bilevel \
|
|
-crop x${PIXELS} \
|
|
+repage \
|
|
"${BASENAME}_${TAPE_WIDTH}mm_%d.${EXTENSION}"
|
|
|
|
echo "Done! Slices saved as: ${BASENAME}_${TAPE_WIDTH}mm_*.${EXTENSION}"
|