#!/usr/bin/env bash # auto fix issues with my scanner input="$3" color=$(magick "$input" -format "%[hex:u.p{100,-1}]" info:) tmp=$(mktemp --suffix=.png) magick "$input" -page +0-100 -background \#$color -flatten -auto-level $tmp magick $tmp -quality 100 "${input%.*}.pdf" rm -rf $tmp "$input"