Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/impacts.to.git
#!/bin/bash

source $HOME/bin/build-template

DEPENDENCIES=(
  "convert,https://imagemagick.org/"
)

# -----------------------------------------------------------------------------
# Perform all commands that the script requires.
#
# @return 0 - Indicate to terminate the script with non-zero exit level
# @return 1 - All tasks completed successfully (default)
# -----------------------------------------------------------------------------
execute() {
  local -r DIR_SRC="$HOME/dev/writing/impacts/renders/output"
  local -r DIR_DST="images"
  local -r WIDTH_X=300

  $log "Downscale renders to ${WIDTH_X}px"

  for i in $(find ${DIR_SRC} -type f -name "page-??.png"); do
    file_src="$(basename ${i})"
    file_dst="$(basename ${file_src} .png).jpg"
    path_dst="${DIR_DST}/${file_dst}"

    # Add a drop-shadow to the images
    $log "Processing ${file_src} to ${path_dst}"
		convert "$i" \
			\( +clone -background "#202020" -shadow 80x3+10+10 -channel RGBA -blur 0x20 \) \
			+swap -background transparent -layers merge -dither None -depth 8 \
			-resize "${WIDTH_X}x" -background "#fefefe" \
			-flatten +repage -trim - | \
			pngtopnm - | \
				jpeg-recompress \
					--quiet --strip --ppm --quality "veryhigh" \
					--accurate --method ssim - \
					"${path_dst}"
  done

  return 1
}

main "$@"