189 lines
No EOL
6 KiB
Bash
189 lines
No EOL
6 KiB
Bash
#!/usr/bin/env bash
|
|
# this title font is insanely over the top for what this does
|
|
# ▄████▄ ▓█████▄ ██████ ▄████▄ ██▀███ ██▓ ██▓███ ▄▄▄█████▓
|
|
# ▒██▀ ▀█ ▒██▀ ██▌ ▒██ ▒ ▒██▀ ▀█ ▓██ ▒ ██▒▓██▒▓██░ ██▒▓ ██▒ ▓▒
|
|
# ▒▓█ ▄ ░██ █▌ ░ ▓██▄ ▒▓█ ▄ ▓██ ░▄█ ▒▒██▒▓██░ ██▓▒▒ ▓██░ ▒░
|
|
# ▒▓▓▄ ▄██▒░▓█▄ ▌ ▒ ██▒▒▓▓▄ ▄██▒▒██▀▀█▄ ░██░▒██▄█▓▒ ▒░ ▓██▓ ░
|
|
# ▒ ▓███▀ ░░▒████▓ ▒██████▒▒▒ ▓███▀ ░░██▓ ▒██▒░██░▒██▒ ░ ░ ▒██▒ ░
|
|
# ░ ░▒ ▒ ░ ▒▒▓ ▒ ▒ ▒▓▒ ▒ ░░ ░▒ ▒ ░░ ▒▓ ░▒▓░░▓ ▒▓▒░ ░ ░ ▒ ░░
|
|
# ░ ▒ ░ ▒ ▒ ░ ░▒ ░ ░ ░ ▒ ░▒ ░ ▒░ ▒ ░░▒ ░ ░
|
|
# ░ ░ ░ ░ ░ ░ ░ ░ ░░ ░ ▒ ░░░ ░
|
|
# ░ ░ ░ ░ ░ ░ ░ ░
|
|
# ░ ░ ░
|
|
#
|
|
# script to make cd jewel case inserts easily
|
|
# by sun https://sx7n8.tech/
|
|
#
|
|
# dependencies are:
|
|
# imagemagick, bash
|
|
|
|
# TODO: add super jewel box and "digipack"
|
|
# TODO: make code good
|
|
|
|
|
|
# general info
|
|
EXT="jpg" # DO NOT CHANGE THIS TO PNG
|
|
TMP="/tmp"
|
|
NAME=work."$EXT"
|
|
COVER="meow"
|
|
rm -f "$TMP"/"$NAME"
|
|
|
|
|
|
# message that gets printed if theres missing or unexistant arguments
|
|
USAGE="Usage: $0 -p <paper> -c <cover> [OPTIONS] [OUTPUT]\nTry '$0 -h' for more information"
|
|
|
|
|
|
# help message
|
|
HELP="Script to create printable CD jewel case inserts.
|
|
Options:
|
|
|
|
flags extra options
|
|
-------------------------------------------------------------
|
|
-h: shows this message and exits none
|
|
-p: sets paper format. (necessary) a4|letter
|
|
-c: sets the album cover path. (necessary) <path>
|
|
-b: sets the back info. (necessary) no|image
|
|
-i: sets the back image (nec. if b = image) <path>
|
|
-m: sets a border around everything, width(px)
|
|
"
|
|
|
|
###########################################
|
|
### TODO: make the code and io not suck ###
|
|
###########################################
|
|
|
|
# getops argument handling
|
|
while getopts "hp:c:b:i:m:" o; do
|
|
case "${o}" in
|
|
h)
|
|
echo -e "$HELP"
|
|
exit
|
|
;;
|
|
|
|
p)
|
|
if [[ "$OPTARG" = "a4" || "$OPTARG" = "letter" ]]; then
|
|
PAPER="$OPTARG"
|
|
else
|
|
echo "Invalid paper type. Run '$0 -h' for info."
|
|
exit 1
|
|
fi
|
|
;;
|
|
|
|
c)
|
|
if [ -f "$OPTARG" ]; then
|
|
COVER="$OPTARG"
|
|
COVERSIZE="$(identify -format "%w" "$COVER")"
|
|
else
|
|
echo "Invalid file. Run '$0 -h' for info."
|
|
exit 1
|
|
fi
|
|
;;
|
|
|
|
b)
|
|
if [[ "$OPTARG" = "no" || "$OPTARG" = "image" ]]; then
|
|
BACKTYPE=$OPTARG
|
|
else
|
|
echo "Invalid back type. Run '$0 -h' for info."
|
|
exit 1
|
|
fi
|
|
;;
|
|
|
|
i)
|
|
if [[ "$BACKTYPE" = "image" ]]; then
|
|
BACKIMG=$OPTARG
|
|
else
|
|
echo "Invalid back type. Run '$0 -h' for info."
|
|
exit 1
|
|
fi
|
|
if [ -f "$OPTARG" ]; then
|
|
:
|
|
else
|
|
echo "Invalid file. Run '$0 -h' for info."
|
|
exit 1
|
|
fi
|
|
;;
|
|
|
|
m)
|
|
BORDER="TRUE"
|
|
BORDER_WIDTH="$OPTARG"
|
|
;;
|
|
|
|
*)
|
|
echo -e "$USAGE"
|
|
exit
|
|
;;
|
|
esac
|
|
done
|
|
|
|
|
|
# print the usage message if there aren't enough arguments
|
|
if [ $# -lt 6 ]; then
|
|
echo -e "$USAGE"
|
|
exit
|
|
fi
|
|
|
|
|
|
# function to convert mm to px with dpi
|
|
CONVERT() { awk -v mm="$1" -v dpi="$2" 'BEGIN{printf("%d", mm/25.4*dpi + 0.5)}'; }
|
|
|
|
|
|
# DPI of paper
|
|
DPI="300"
|
|
|
|
|
|
# cover art size (mm)
|
|
CO_MM="120"
|
|
CO_PX="$(CONVERT "$CO_MM" "$DPI")"
|
|
|
|
|
|
# Width and Height of paper in mm
|
|
A4MM_W="210"
|
|
A4MM_H="297"
|
|
LTMM_W="216"
|
|
LTMM_H="279"
|
|
|
|
|
|
# same values in pixels
|
|
A4PX="$(CONVERT "$A4MM_W" "$DPI")x$(CONVERT "$A4MM_H" "$DPI")"
|
|
LTPX="$(CONVERT "$LTMM_W" "$DPI")x$(CONVERT "$LTMM_H" "$DPI")"
|
|
|
|
|
|
# assign to the 'size' variable the right value
|
|
if [ "$PAPER" = "a4" ]; then
|
|
SIZE=$A4PX
|
|
elif [ "$PAPER" = "letter" ]; then
|
|
SIZE=$LTPX
|
|
else
|
|
echo "what the fuck did you do"
|
|
exit
|
|
fi
|
|
|
|
|
|
# failsafe
|
|
# if [ "$COVER" = "meow" ];
|
|
# echo -e "$USAGE"
|
|
# fi
|
|
|
|
|
|
# create a blank file with the specified paper type
|
|
magick -colorspace sRGB -type TrueColor -depth 8 -size $SIZE canvas:white "$TMP"/"$NAME" > /dev/null
|
|
|
|
|
|
# draws border (rectangle)
|
|
if [ "$BORDER" = "TRUE" ]; then
|
|
INSET=$((BORDER_WIDTH / 2))
|
|
magick "$TMP/$NAME" \( -size $((CO_PX + 2 * BORDER_WIDTH))x$((CO_PX * 2 + 2 * BORDER_WIDTH)) xc:none -colorspace sRGB -type TrueColor -depth 8 -fill none -stroke black -strokewidth $BORDER_WIDTH -draw "rectangle $INSET,$INSET $((CO_PX + BORDER_WIDTH - 1)),$((CO_PX * 2 + BORDER_WIDTH - 1))" \) -gravity center -composite "$TMP/$NAME"
|
|
fi
|
|
|
|
|
|
# add the cover art set to the right size, rotated left by 90d and shifted up by (cover art size) / 2
|
|
# TODO: change rotation to a variable to allow different folding points via argument
|
|
# TODO: make command multi-line for readibility
|
|
magick -colorspace sRGB -type TrueColor -depth 8 "$TMP"/"$NAME" \( "$COVER" -resize ${CO_PX}x${CO_PX} -rotate 270 \) -gravity center -geometry +0-$((CO_PX/2)) -composite "$TMP"/"$NAME" > /dev/null
|
|
|
|
|
|
# adds back
|
|
if [ "$BACKTYPE" = "image" ]; then
|
|
magick -colorspace sRGB -type TrueColor -depth 8 "$TMP"/"$NAME" \( "$BACKIMG" -resize ${CO_PX}x${CO_PX} -rotate 270 \) -gravity center -geometry +0+$((CO_PX/2)) -composite "$TMP"/"$NAME" > /dev/null
|
|
else
|
|
:
|
|
fi |