various stuff
This commit is contained in:
parent
57a56502b2
commit
705bef0aa3
1 changed files with 83 additions and 24 deletions
97
cdscript.sh
97
cdscript.sh
|
@ -13,11 +13,11 @@
|
||||||
# TODO:
|
# TODO:
|
||||||
# - !!! Add support for back insert !!!
|
# - !!! Add support for back insert !!!
|
||||||
# - Remove bugs
|
# - Remove bugs
|
||||||
# - Add more paper types
|
# - Add more paper types DONE
|
||||||
# - Make DPI a command line option
|
# - Make DPI a command line option DONE
|
||||||
# - Add different folding points for inserts
|
# - Add different folding points for inserts
|
||||||
# - Clean up code and add more comments
|
# - Clean up code and add more comments
|
||||||
# - Improve input and output further
|
# - Improve input and output further DONE
|
||||||
|
|
||||||
|
|
||||||
# usage message
|
# usage message
|
||||||
|
@ -28,22 +28,28 @@ USAGE="Usage: $0 -p <paper> -c <cover> -b <back> [-i <back_image>] [-m <border>]
|
||||||
HELP="Script to create printable CD jewel case inserts
|
HELP="Script to create printable CD jewel case inserts
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
$0 -p <paper> -c <cover> -b <back> [-i <back_image>] [-m <border>] -o <output>
|
$0 -p <paper> -c <cover> -b <back> [-i <back_image>] [-m <border>] [-d DPI] -o <output>
|
||||||
|
|
||||||
Required options:
|
Required options:
|
||||||
-p Paper format a4 | letter
|
-p Paper format a4 | letter | legal
|
||||||
-c Album cover path Path to cover image
|
-c Album cover path Path to cover image
|
||||||
-b Back type no | image
|
-b Back type no | image
|
||||||
-o Output file Path to save the resulting insert (NO PNG)
|
-o Output file Path to save the resulting insert (NO PNG)
|
||||||
|
|
||||||
|
|
||||||
Optional options:
|
Optional options:
|
||||||
-i Back image path Required if back type is 'image'
|
-i Back image path Required if back type is 'image'
|
||||||
-m Border width (px) Adds a border around the cover/back
|
-m Border width (px) Adds a border around the cover/back
|
||||||
|
-d DPI Desired DPI of the output
|
||||||
|
|
||||||
DO NOT USE PNG FOR OUTPUT
|
DO NOT USE PNG FOR OUTPUT
|
||||||
"
|
"
|
||||||
|
|
||||||
|
|
||||||
|
# default DPI
|
||||||
|
DPI="300"
|
||||||
|
|
||||||
|
|
||||||
# error function
|
# error function
|
||||||
error() {
|
error() {
|
||||||
echo -e "Error: $1" >&2
|
echo -e "Error: $1" >&2
|
||||||
|
@ -68,8 +74,16 @@ check_output_file() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# number check
|
||||||
|
check_dpi() {
|
||||||
|
if ! [[ "$var" =~ ^[1-9][0-9]*$ ]]; then
|
||||||
|
error "DPI is not a valid number"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# getops argument handling
|
# getops argument handling
|
||||||
while getopts "hp:c:b:i:m:o:" o; do
|
while getopts "hp:c:b:i:m:o:d:" o; do
|
||||||
case "${o}" in
|
case "${o}" in
|
||||||
h)
|
h)
|
||||||
echo -e "$HELP"
|
echo -e "$HELP"
|
||||||
|
@ -107,6 +121,11 @@ while getopts "hp:c:b:i:m:o:" o; do
|
||||||
check_output_file "$OPTARG"
|
check_output_file "$OPTARG"
|
||||||
OUTPUT="$OPTARG"
|
OUTPUT="$OPTARG"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
d)
|
||||||
|
check_dpi "$OPTARG"
|
||||||
|
DPI="$OPTARG"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "$USAGE"
|
echo -e "$USAGE"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -127,10 +146,6 @@ done
|
||||||
CONVERT() { awk -v mm="$1" -v dpi="$2" 'BEGIN{printf("%d", mm/25.4*dpi + 0.5)}'; }
|
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)
|
# cover art size (mm)
|
||||||
CO_MM="120"
|
CO_MM="120"
|
||||||
CO_PX="$(CONVERT "$CO_MM" "$DPI")"
|
CO_PX="$(CONVERT "$CO_MM" "$DPI")"
|
||||||
|
@ -143,10 +158,14 @@ A4MM_H="297"
|
||||||
LTMM_W="216"
|
LTMM_W="216"
|
||||||
LTMM_H="279"
|
LTMM_H="279"
|
||||||
|
|
||||||
|
LGMM_W="216"
|
||||||
|
LGMM_H="279"
|
||||||
|
|
||||||
|
|
||||||
# same values in pixels
|
# same values in pixels
|
||||||
A4PX="$(CONVERT "$A4MM_W" "$DPI")x$(CONVERT "$A4MM_H" "$DPI")"
|
A4PX="$(CONVERT "$A4MM_W" "$DPI")x$(CONVERT "$A4MM_H" "$DPI")"
|
||||||
LTPX="$(CONVERT "$LTMM_W" "$DPI")x$(CONVERT "$LTMM_H" "$DPI")"
|
LTPX="$(CONVERT "$LTMM_W" "$DPI")x$(CONVERT "$LTMM_H" "$DPI")"
|
||||||
|
LGPX="$(CONVERT "$LGMM_W" "$DPI")x$(CONVERT "$LGMM_H" "$DPI")"
|
||||||
|
|
||||||
|
|
||||||
# assign to the 'size' variable the right value
|
# assign to the 'size' variable the right value
|
||||||
|
@ -154,9 +173,8 @@ if [ "$PAPER" = "a4" ]; then
|
||||||
SIZE=$A4PX
|
SIZE=$A4PX
|
||||||
elif [ "$PAPER" = "letter" ]; then
|
elif [ "$PAPER" = "letter" ]; then
|
||||||
SIZE=$LTPX
|
SIZE=$LTPX
|
||||||
else
|
elif [ "$PAPER" = "legal" ]; then
|
||||||
echo "what the fuck did you do"
|
SIZE=$LGPX
|
||||||
exit
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,16 +186,57 @@ magick -colorspace sRGB -type TrueColor -depth 8 -size $SIZE canvas:white "$OUTP
|
||||||
if [ "$BORDER" = "TRUE" ]; then
|
if [ "$BORDER" = "TRUE" ]; then
|
||||||
INSET=$((BORDER_WIDTH / 2))
|
INSET=$((BORDER_WIDTH / 2))
|
||||||
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""
|
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
|
# adds the cover
|
||||||
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
|
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 # if the back is an image
|
||||||
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
|
# adds image
|
||||||
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
|
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 # if the back is not an image
|
||||||
|
|
||||||
|
# adds white square
|
||||||
|
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