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
|
# general info
|
||||||
EXT="jpg" # DO NOT CHANGE THIS TO PNG
|
# EXT="jpg" # DO NOT CHANGE THIS TO PNG
|
||||||
TMP="/tmp"
|
# TMP="/tmp"
|
||||||
NAME=work."$EXT"
|
# NAME=work."$EXT"
|
||||||
COVER="meow"
|
# rm -f "$OUTPUT"
|
||||||
rm -f "$TMP"/"$NAME"
|
|
||||||
|
|
||||||
|
|
||||||
# message that gets printed if theres missing or unexistant arguments
|
# 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 message
|
||||||
HELP="Script to create printable CD jewel case inserts.
|
HELP="Script to create printable CD jewel case inserts
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
flags extra options
|
flags extra options
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
-h: shows this message and exits none
|
-h: shows this message and exits none
|
||||||
-p: sets paper format. (necessary) a4|letter
|
-p: sets paper format (necessary) a4|letter
|
||||||
-c: sets the album cover path. (necessary) <path>
|
-c: sets the album cover path (necessary) <path>
|
||||||
-b: sets the back info. (necessary) no|image
|
-b: sets the back info (necessary) no|image
|
||||||
-i: sets the back image (nec. if b = image) <path>
|
-i: sets the back image (nec. is b = image) <path>
|
||||||
-m: sets a border around everything, width(px)
|
-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
|
# 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
|
case "${o}" in
|
||||||
h)
|
h)
|
||||||
echo -e "$HELP"
|
echo -e "$HELP"
|
||||||
|
|
@ -89,7 +91,7 @@ while getopts "hp:c:b:i:m:" o; do
|
||||||
|
|
||||||
i)
|
i)
|
||||||
if [[ "$BACKTYPE" = "image" ]]; then
|
if [[ "$BACKTYPE" = "image" ]]; then
|
||||||
BACKIMG=$OPTARG
|
BACKIMG="$OPTARG"
|
||||||
else
|
else
|
||||||
echo "Invalid back type. Run '$0 -h' for info."
|
echo "Invalid back type. Run '$0 -h' for info."
|
||||||
exit 1
|
exit 1
|
||||||
|
|
@ -107,6 +109,15 @@ while getopts "hp:c:b:i:m:" o; do
|
||||||
BORDER_WIDTH="$OPTARG"
|
BORDER_WIDTH="$OPTARG"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
o)
|
||||||
|
if [ -f "$OPTARG" ]; then
|
||||||
|
echo -e "Error: file already exists."
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
OUTPUT="$OPTARG"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo -e "$USAGE"
|
echo -e "$USAGE"
|
||||||
exit
|
exit
|
||||||
|
|
@ -115,10 +126,19 @@ while getopts "hp:c:b:i:m:" o; do
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# print the usage message if there aren't enough arguments
|
# check if something is missing
|
||||||
if [ $# -lt 6 ]; then
|
if [ -z "$PAPER" ] || [ -z "$COVER" ] || [ -z "$BACKTYPE" ] || [ -z "$OUTPUT" ]; then
|
||||||
|
echo -e "Error: missing options"
|
||||||
echo -e "$USAGE"
|
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
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -158,32 +178,26 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# failsafe
|
|
||||||
# if [ "$COVER" = "meow" ];
|
|
||||||
# echo -e "$USAGE"
|
|
||||||
# fi
|
|
||||||
|
|
||||||
|
|
||||||
# create a blank file with the specified paper type
|
# 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)
|
# draws border (rectangle)
|
||||||
if [ "$BORDER" = "TRUE" ]; then
|
if [ "$BORDER" = "TRUE" ]; then
|
||||||
INSET=$((BORDER_WIDTH / 2))
|
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
|
fi
|
||||||
|
|
||||||
|
|
||||||
# add the cover art set to the right size, rotated left by 90d and shifted up by (cover art size) / 2
|
# 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: change rotation to a variable to allow different folding points via argument
|
||||||
# TODO: make command multi-line for readibility
|
# 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
|
# adds back
|
||||||
if [ "$BACKTYPE" = "image" ]; then
|
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
|
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
|
fi
|
||||||
Loading…
Add table
Reference in a new issue