changed indentation

main
Antonio De Lucreziis 2 years ago
parent 866964f083
commit 78237dca71

@ -3,18 +3,18 @@
set -euo pipefail set -euo pipefail
function show_usage { function show_usage {
cat <<-END cat <<-END
usage: $0 [OPTIONS...] input_file output_file usage: $0 [OPTIONS...] input_file output_file
Converts a PDF file to a series of JPEG images using convert to Converts a PDF file to a series of JPEG images using convert to
reduce the quality and then merges back the result in a single pdf reduce the quality and then merges back the result in a single pdf
options: options:
-q, --quality Set the JPEG quality (default: 75) -q, --quality Set the JPEG quality (default: 75)
-v, --verbose Enable verbose output -v, --verbose Enable verbose output
-h, --help Display this help message -h, --help Display this help message
END END
exit 1 exit 1
} }
quality=75 quality=75
@ -22,33 +22,33 @@ verbose=false
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]
do do
key="$1" key="$1"
case $key in case $key in
-q|--quality) -q|--quality)
quality="$2" quality="$2"
shift # past argument shift # past argument
shift # past value shift # past value
;; ;;
-v|--verbose) -v|--verbose)
verbose=true verbose=true
shift # past argument shift # past argument
;; ;;
-h|--help) -h|--help)
show_usage show_usage
;; ;;
-*) -*)
echo "Unknown option: $key" echo "Unknown option: $key"
show_usage show_usage
;; ;;
*) *)
break break
;; ;;
esac esac
done done
if [ -z "$1" ] || [ -z "$2" ]; then if [ -z "$1" ] || [ -z "$2" ]; then
show_usage show_usage
fi fi
input_file="$1" input_file="$1"
@ -57,9 +57,9 @@ output_file="$2"
temp_pages_dir="$(mktemp -d)" temp_pages_dir="$(mktemp -d)"
function logf { function logf {
if [ "$verbose" = true ]; then if [ "$verbose" = true ]; then
printf "$@" printf "$@"
fi fi
} }
logf "Converting \"$input_file\" to \"$output_file\"\n" logf "Converting \"$input_file\" to \"$output_file\"\n"
@ -70,18 +70,18 @@ logf "Processing $page_count pages\n"
start=$(date +%s.%N) start=$(date +%s.%N)
for i in $(seq 0 $((page_count-1))); do for i in $(seq 0 $((page_count-1))); do
iter_start=$(date +%s.%N) iter_start=$(date +%s.%N)
convert -density 300 -quality "$quality" "${input_file}[$i]" "$temp_pages_dir/$i.jpg" convert -density 300 -quality "$quality" "${input_file}[$i]" "$temp_pages_dir/$i.jpg"
# Compute estimated remaining time # Compute estimated remaining time
end=$(date +%s.%N) end=$(date +%s.%N)
elapsed=$(echo "$end - $start" | bc) elapsed=$(echo "$end - $start" | bc)
iter_elapsed=$(echo "$end - $iter_start" | bc) iter_elapsed=$(echo "$end - $iter_start" | bc)
remaining=$(echo "($elapsed / ($i + 1)) * ($page_count - $i)" | bc) remaining=$(echo "($elapsed / ($i + 1)) * ($page_count - $i)" | bc)
remaining_fmt=$(printf "%02d:%02d:%02d" $((remaining/3600)) $((remaining/60)) $((remaining%60))) remaining_fmt=$(printf "%02d:%02d:%02d" $((remaining/3600)) $((remaining/60)) $((remaining%60)))
logf "Compressed page $((i+1)) in $(printf '%.2f' "$iter_elapsed")s (estimated remaining time $remaining_fmt)\n" logf "Compressed page $((i+1)) in $(printf '%.2f' "$iter_elapsed")s (estimated remaining time $remaining_fmt)\n"
done done
logf "Merging compressed pages to a single PDF\n" logf "Merging compressed pages to a single PDF\n"

Loading…
Cancel
Save