Fixed bug for auto-orient and separate dir

This commit is contained in:
dbroqua 2020-05-13 17:47:13 +02:00
parent f2922581c8
commit d23cc0079f

View file

@ -24,8 +24,8 @@
# Your choices # Your choices
MAXWIDTH=800 MAXWIDTH=800
MAXHEIGHT=600 MAXHEIGHT=600
COVERWIDTH=520 COVERWIDTH=955
COVERHEIGHT=245 COVERHEIGHT=450
# Defining some generic variables # Defining some generic variables
COVERFILE="cover.jpg" COVERFILE="cover.jpg"
@ -33,6 +33,8 @@ COVERRATIO=`bc -l <<< "${COVERWIDTH}/${COVERHEIGHT}"`
LOGO=~/template/logo.png LOGO=~/template/logo.png
IMAGERATIO=`bc -l <<< "${MAXWIDTH}/${MAXHEIGHT}"` IMAGERATIO=`bc -l <<< "${MAXWIDTH}/${MAXHEIGHT}"`
DEST='resized' DEST='resized'
DESTJPG="${DEST}/JPG"
DESTPNG="${DEST}/PNG"
OPTIONS='-depth 8 -quality 90 -strip -interlace Plane' OPTIONS='-depth 8 -quality 90 -strip -interlace Plane'
BORDERWIDTH=12 BORDERWIDTH=12
BORDERTHINWIDTH=1 BORDERTHINWIDTH=1
@ -47,8 +49,11 @@ RESET="\033[0m"
# If destination does not exists, create it # If destination does not exists, create it
if [ ! -d ${DEST} ] ; then if [ ! -d ${DESTJPG} ] ; then
mkdir ${DEST} mkdir -p ${DESTJPG}
fi
if [ ! -d ${DESTPNG} ] ; then
mkdir -p ${DESTPNG}
fi fi
# For each files # For each files
@ -59,10 +64,16 @@ for image in {*.jpg,*.JPG} ; do
continue continue
fi fi
if [ `exiftool -Orientation -n "${image}" | cut -d":" -f2|cut -d' ' -f2` -eq 6 ] ; then
convert -auto-orient ${image} ${image}
fi
# Extract image dimensions # Extract image dimensions
WIDTH=`identify -format "%[fx:w]" "${image}"` WIDTH=`identify -format "%[fx:w]" "${image}"`
HEIGHT=`identify -format "%[fx:h]" "${image}"` HEIGHT=`identify -format "%[fx:h]" "${image}"`
echo ${WIDTH}x${HEIGHT}
# Compute image ratio # Compute image ratio
TMPIMAGERATIO=`bc -l <<< "${WIDTH}/${HEIGHT}"` TMPIMAGERATIO=`bc -l <<< "${WIDTH}/${HEIGHT}"`
@ -123,10 +134,10 @@ for image in {*.jpg,*.JPG} ; do
"${image}" \ "${image}" \
-fill transparent -stroke black -strokewidth ${BORDERWIDTH} -draw "stroke-linecap square path 'M $((${BORDERWIDTH}/2)),0 L ${BORDERLOWERLEFT} L ${BORDERLOWERRIGHT} L ${BORDERUPPERRIGHT} L ${BORDERUPPERLEFT} Z'" \ -fill transparent -stroke black -strokewidth ${BORDERWIDTH} -draw "stroke-linecap square path 'M $((${BORDERWIDTH}/2)),0 L ${BORDERLOWERLEFT} L ${BORDERLOWERRIGHT} L ${BORDERUPPERRIGHT} L ${BORDERUPPERLEFT} Z'" \
-fill transparent -stroke white -strokewidth ${BORDERTHINWIDTH} -draw "stroke-linecap square path 'M ${THINBORDERUPPERLEFT} L ${THINBORDERLOWERLEFT} L ${THINBORDERLOWERRIGHT} L ${THINBORDERUPPERRIGHT} L ${THINBORDERUPPERLEFT} Z'" \ -fill transparent -stroke white -strokewidth ${BORDERTHINWIDTH} -draw "stroke-linecap square path 'M ${THINBORDERUPPERLEFT} L ${THINBORDERLOWERLEFT} L ${THINBORDERLOWERRIGHT} L ${THINBORDERUPPERRIGHT} L ${THINBORDERUPPERLEFT} Z'" \
"${DEST}/${image}" "${DESTJPG}/${image}"
# Add logo on imagedow # Add logo on imagedow
composite ${OPTIONS} -gravity SouthEast "${LOGO}" "${DEST}/${image}" "${DEST}/${image}" composite ${OPTIONS} -gravity SouthEast "${LOGO}" "${DESTJPG}/${image}" "${DESTJPG}/${image}"
# Create same version but in PNG and with box shadow # Create same version but in PNG and with box shadow
echo -e " -> ${BLUE}Create PNG version${RESET}" echo -e " -> ${BLUE}Create PNG version${RESET}"
@ -140,12 +151,12 @@ for image in {*.jpg,*.JPG} ; do
-fill transparent -stroke white -strokewidth ${BORDERTHINWIDTH} -draw "stroke-linecap square path 'M ${THINBORDERUPPERLEFT} L ${THINBORDERLOWERLEFT} L ${THINBORDERLOWERRIGHT} L ${THINBORDERUPPERRIGHT} L ${THINBORDERUPPERLEFT} Z'" \ -fill transparent -stroke white -strokewidth ${BORDERTHINWIDTH} -draw "stroke-linecap square path 'M ${THINBORDERUPPERLEFT} L ${THINBORDERLOWERLEFT} L ${THINBORDERLOWERRIGHT} L ${THINBORDERUPPERRIGHT} L ${THINBORDERUPPERLEFT} Z'" \
\( +clone -background black -shadow 80x3+2+2 \) \ \( +clone -background black -shadow 80x3+2+2 \) \
+swap -background transparent -layers merge +repage \ +swap -background transparent -layers merge +repage \
"${DEST}/${filename}.png" "${DESTPNG}/${filename}.png"
# Add logo on imagedow # Add logo on imagedow
composite ${OPTIONS} -gravity SouthEast "${LOGO}" "${DEST}/${filename}.png" "${DEST}/${filename}.png" composite ${OPTIONS} -gravity SouthEast "${LOGO}" "${DESTPNG}/${filename}.png" "${DESTPNG}/${filename}.png"
convert "${DEST}/${filename}.png" -type TrueColorAlpha -quality 90 -format PNG32 -background transparent -depth 8 -strip "${DEST}/${filename}.png" convert "${DESTPNG}/${filename}.png" -type TrueColorAlpha -quality 90 -format PNG32 -background transparent -depth 8 -strip "${DESTPNG}/${filename}.png"
fi fi
fi fi
done done