Added border for images
This commit is contained in:
parent
81bd612dae
commit
bc396d9d8f
1 changed files with 69 additions and 31 deletions
|
@ -29,10 +29,14 @@ COVERHEIGHT=245
|
||||||
|
|
||||||
# Defining some generic variables
|
# Defining some generic variables
|
||||||
COVERFILE="cover.jpg"
|
COVERFILE="cover.jpg"
|
||||||
COVERRATIO=$((${COVERWIDTH}/${COVERHEIGHT}))
|
COVERRATIO=`bc -l <<< "${COVERWIDTH}/${COVERHEIGHT}"`
|
||||||
LOGO=~/template/logo.png
|
LOGO=~/template/logo.png
|
||||||
|
IMAGERATIO=`bc -l <<< "${MAXWIDTH}/${MAXHEIGHT}"`
|
||||||
DEST='resized'
|
DEST='resized'
|
||||||
OPTIONS='-depth 8 -quality 90 -strip -interlace Plane'
|
OPTIONS='-depth 8 -quality 90 -strip -interlace Plane'
|
||||||
|
BORDERWIDTH=12
|
||||||
|
BORDERTHINWIDTH=1
|
||||||
|
BORDERTHINPLACEMENT=8
|
||||||
|
|
||||||
# Defining some colors for log()
|
# Defining some colors for log()
|
||||||
RED="\E[31m"
|
RED="\E[31m"
|
||||||
|
@ -49,35 +53,49 @@ fi
|
||||||
|
|
||||||
# For each files
|
# For each files
|
||||||
for image in {*.jpg,*.JPG} ; do
|
for image in {*.jpg,*.JPG} ; do
|
||||||
|
if [ "${image}" != "*.JPG" ] && [ "${image}" != "*.jpg" ] ; then
|
||||||
if [ ! -f "${image}" ] ; then
|
if [ ! -f "${image}" ] ; then
|
||||||
echo -e "${RED}# No file found in ${PWD}${RESET}"
|
echo -e "${RED}# ${image} is not a valid image file in ${PWD}${RESET}"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Convert cover
|
|
||||||
if [ "${image}" == "${COVERFILE}" ] ; then
|
|
||||||
echo -e "${GREEN}Converting cover file${RESET}"
|
|
||||||
|
|
||||||
# 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}`
|
||||||
|
|
||||||
# Compute image ratio
|
# Compute image ratio
|
||||||
IMAGERATIO=$((${WIDTH}/${HEIGHT}))
|
TMPIMAGERATIO=`bc -l <<< "${WIDTH}/${HEIGHT}"`
|
||||||
|
|
||||||
# Define temporary image size (used for crop)
|
# Define image size
|
||||||
TMPWIDTH=${WIDTH}
|
NEWWIDTH=${WIDTH}
|
||||||
TMPHEIGHT=${HEIGHT}
|
NEWHEIGHT=${HEIGHT}
|
||||||
|
|
||||||
|
# Compute new image size based on image type
|
||||||
|
if [ "${image}" == "${COVERFILE}" ] ; then
|
||||||
# Compute temporary with or height to crop correctly image
|
# Compute temporary with or height to crop correctly image
|
||||||
if [ "${COVERRATIO}" -gt "${IMAGERATIO}" ] ; then
|
if [ "${COVERRATIO}" -gt "${TMPIMAGERATIO}" ] ; then
|
||||||
TMPHEIGHT=$((${WIDTH}*${COVERHEIGHT}/${COVERWIDTH}))
|
NEWHEIGHT=$((${WIDTH}*${COVERHEIGHT}/${COVERWIDTH}))
|
||||||
else
|
else
|
||||||
TMPWIDTH=$((${HEIGHT}*${COVERWIDTH}/${COVERHEIGHT}))
|
NEWWIDTH=$((${HEIGHT}*${COVERWIDTH}/${COVERHEIGHT}))
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Compute temporary with or height to crop correctly image
|
||||||
|
RATIO=`echo ${IMAGERATIO}'<'${TMPIMAGERATIO} | bc -l`
|
||||||
|
if [ ${RATIO} -eq 1 ] ; then
|
||||||
|
NEWWIDTH=${MAXWIDTH}
|
||||||
|
NEWHEIGHT=`LC_NUMERIC="en_US.UTF-8" printf "%.0f" $(bc -l <<< "scale=1; ${HEIGHT}*${NEWWIDTH}/${WIDTH}")`
|
||||||
|
else
|
||||||
|
NEWHEIGHT=${MAXHEIGHT}
|
||||||
|
NEWWIDTH=`LC_NUMERIC="en_US.UTF-8" printf "%.0f" $(bc -l <<< "scale=1; ${WIDTH}*${NEWHEIGHT}/${HEIGHT}")`
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Convert cover
|
||||||
|
if [ "${image}" == "${COVERFILE}" ] ; then
|
||||||
|
echo -e "${GREEN}Converting cover file${RESET}"
|
||||||
|
|
||||||
# Crop image with the good ratio
|
# Crop image with the good ratio
|
||||||
convert -gravity Center -crop ${TMPWIDTH}x${TMPHEIGHT}+0+0 +repage ${image} /tmp/${image}
|
convert -gravity Center -crop ${NEWWIDTH}x${NEWHEIGHT}+0+0 +repage ${image} /tmp/${image}
|
||||||
|
|
||||||
# Rezise cover and save it
|
# Rezise cover and save it
|
||||||
convert ${OPTIONS} -resize ${COVERWIDTH}x${COVERHEIGHT} /tmp/${image} ${DEST}/${image}
|
convert ${OPTIONS} -resize ${COVERWIDTH}x${COVERHEIGHT} /tmp/${image} ${DEST}/${image}
|
||||||
|
@ -87,7 +105,27 @@ for image in {*.jpg,*.JPG} ; do
|
||||||
else
|
else
|
||||||
echo -e "${RED}Converting image ${image}${RESET}"
|
echo -e "${RED}Converting image ${image}${RESET}"
|
||||||
|
|
||||||
convert -resize ${MAXWIDTH}x${MAXHEIGHT} "${image}" "${DEST}/${image}"
|
# Compute positions for black border
|
||||||
|
BORDERUPPERLEFT=$((${BORDERWIDTH}/2)),$((${BORDERWIDTH}/2))
|
||||||
|
BORDERLOWERLEFT=$((${BORDERWIDTH}/2)),$((${NEWHEIGHT} - ${BORDERWIDTH}/2))
|
||||||
|
BORDERLOWERRIGHT=$((${NEWWIDTH} - ${BORDERWIDTH}/2)),$((${NEWHEIGHT} - ${BORDERWIDTH}/2))
|
||||||
|
BORDERUPPERRIGHT=$((${NEWWIDTH} - ${BORDERWIDTH}/2)),$((${BORDERWIDTH}/2))
|
||||||
|
|
||||||
|
# Compute positions for white border
|
||||||
|
THINBORDERUPPERLEFT=${BORDERTHINPLACEMENT},${BORDERTHINPLACEMENT}
|
||||||
|
THINBORDERLOWERLEFT=${BORDERTHINPLACEMENT},$((${NEWHEIGHT}-${BORDERTHINPLACEMENT} ))
|
||||||
|
THINBORDERLOWERRIGHT=$((${NEWWIDTH}-${BORDERTHINPLACEMENT} )),$((${NEWHEIGHT}-${BORDERTHINPLACEMENT} ))
|
||||||
|
THINBORDERUPPERRIGHT=$((${NEWWIDTH}-${BORDERTHINPLACEMENT} )),${BORDERTHINPLACEMENT}
|
||||||
|
|
||||||
|
# resize and add border on image
|
||||||
|
convert -resize ${NEWWIDTH}x${NEWHEIGHT} \
|
||||||
|
"${image}" \
|
||||||
|
-fill transparent -stroke black -strokewidth ${BORDERWIDTH} -draw "stroke-linecap square path 'M ${BORDERUPPERLEFT} 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'" \
|
||||||
|
"${DEST}/${image}"
|
||||||
|
|
||||||
|
# Add logo on imagedow
|
||||||
composite ${OPTIONS} -gravity SouthEast "${LOGO}" "${DEST}/${image}" "${DEST}/${image}"
|
composite ${OPTIONS} -gravity SouthEast "${LOGO}" "${DEST}/${image}" "${DEST}/${image}"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue