added ouput, fixed bugs
This commit is contained in:
parent
234b3852d7
commit
0ee7fdee44
1 changed files with 42 additions and 28 deletions
70
cdscript.sh
70
cdscript.sh
|
|
@ -22,29 +22,31 @@
|
|||
|
||||
|
||||
# general info
|
||||
EXT="jpg" # DO NOT CHANGE THIS TO PNG
|
||||
TMP="/tmp"
|
||||
NAME=work."$EXT"
|
||||
COVER="meow"
|
||||
rm -f "$TMP"/"$NAME"
|
||||
# EXT="jpg" # DO NOT CHANGE THIS TO PNG
|
||||
# TMP="/tmp"
|
||||
# NAME=work."$EXT"
|
||||
# rm -f "$OUTPUT"
|
||||
|
||||
|
||||
# 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"
|
||||
USAGE="Usage: $0 [OPTIONS] [OUTPUT]\nTry '$0 -h' for more information"
|
||||
|
||||
|
||||
# help message
|
||||
HELP="Script to create printable CD jewel case inserts.
|
||||
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)
|
||||
-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. is b = image) <path>
|
||||
-m: sets a border around everything width(px)
|
||||
-o: sets output file (necessary) <path>
|
||||
|
||||
!! DO NOT USE PNG !!
|
||||
"
|
||||
|
||||
###########################################
|
||||
|
|
@ -52,7 +54,7 @@ Options:
|
|||
###########################################
|
||||
|
||||
# getops argument handling
|
||||
while getopts "hp:c:b:i:m:" o; do
|
||||
while getopts "hp:c:b:i:m:o:" o; do
|
||||
case "${o}" in
|
||||
h)
|
||||
echo -e "$HELP"
|
||||
|
|
@ -89,7 +91,7 @@ while getopts "hp:c:b:i:m:" o; do
|
|||
|
||||
i)
|
||||
if [[ "$BACKTYPE" = "image" ]]; then
|
||||
BACKIMG=$OPTARG
|
||||
BACKIMG="$OPTARG"
|
||||
else
|
||||
echo "Invalid back type. Run '$0 -h' for info."
|
||||
exit 1
|
||||
|
|
@ -107,6 +109,15 @@ while getopts "hp:c:b:i:m:" o; do
|
|||
BORDER_WIDTH="$OPTARG"
|
||||
;;
|
||||
|
||||
o)
|
||||
if [ -f "$OPTARG" ]; then
|
||||
echo -e "Error: file already exists."
|
||||
exit 1
|
||||
else
|
||||
OUTPUT="$OPTARG"
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
echo -e "$USAGE"
|
||||
exit
|
||||
|
|
@ -115,10 +126,19 @@ while getopts "hp:c:b:i:m:" o; do
|
|||
done
|
||||
|
||||
|
||||
# print the usage message if there aren't enough arguments
|
||||
if [ $# -lt 6 ]; then
|
||||
# check if something is missing
|
||||
if [ -z "$PAPER" ] || [ -z "$COVER" ] || [ -z "$BACKTYPE" ] || [ -z "$OUTPUT" ]; then
|
||||
echo -e "Error: missing options"
|
||||
echo -e "$USAGE"
|
||||
exit
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# check if i is missing
|
||||
if [[ "$BACKTYPE" == "image" && -z "$BACKIMG" ]]; then
|
||||
echo -e "Error: missing options"
|
||||
echo -e "$USAGE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
|
|
@ -158,32 +178,26 @@ else
|
|||
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
|
||||
magick -colorspace sRGB -type TrueColor -depth 8 -size $SIZE canvas:white "$OUTPUT" > /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"
|
||||
magick ""$OUTPUT"" \( -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 ""$OUTPUT""
|
||||
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
|
||||
magick -colorspace sRGB -type TrueColor -depth 8 "$OUTPUT" \( "$COVER" -resize ${CO_PX}x${CO_PX} -rotate 270 \) -gravity center -geometry +0-$((CO_PX/2)) -composite "$OUTPUT" > /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
|
||||
magick -colorspace sRGB -type TrueColor -depth 8 "$OUTPUT" \( "$BACKIMG" -resize ${CO_PX}x${CO_PX} -rotate 270 \) -gravity center -geometry +0+$((CO_PX/2)) -composite "$OUTPUT" > /dev/null
|
||||
else
|
||||
:
|
||||
magick -colorspace sRGB -type TrueColor -depth 8 "$OUTPUT" \( -size ${CO_PX}x${CO_PX} xc:'#FFFFFF' \) -gravity center -geometry +0+$((CO_PX/2)) -composite "$OUTPUT" > /dev/null
|
||||
fi
|
||||
Loading…
Add table
Reference in a new issue