From 000ab55426bf2be3cb550309875ff4de4320cf15 Mon Sep 17 00:00:00 2001 From: jo Date: Thu, 12 Dec 2024 13:52:08 +0000 Subject: [PATCH] Update preprocess_png_sticoeureuse.sh --- preprocess_png_sticoeureuse.sh | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/preprocess_png_sticoeureuse.sh b/preprocess_png_sticoeureuse.sh index 9d25cf7..c4f304d 100644 --- a/preprocess_png_sticoeureuse.sh +++ b/preprocess_png_sticoeureuse.sh @@ -53,8 +53,6 @@ while getopts 'i:o:sW:Narfh' flag; do esac done -echo ${input} - if [ "${all}" = "true" ]; then find_all() { first=1 @@ -79,7 +77,7 @@ if [ "${all}" = "true" ]; then cd ${input} fi - all=$(find_all "jpg" "jpeg" "png" "pdf" "PNG" "JPG") + all=$(find_all "jpg" "jpeg" "png" "pdf" "PNG" "JPG" "PDF") OIFS="$IFS" IFS=$'\n' for file in $all; do @@ -89,11 +87,26 @@ if [ "${all}" = "true" ]; then continue fi + if [[ "${file##*.}" = "pdf" || "${file##*.}" = "PDF" ]] ; then + rm_file=true + old_file=$file + + base_file_name=$(basename "${file%.*}") + file=".tmp_${base_file_name}.png" + + magick $old_file $file + fi + if [ "$(( $(identify -format "%w ${turn} %h" ${file}) ))" = "1" ]; then ffmpeg -i ${file} -frames:v 1 -vf scale=-1:719:force_original_aspect_ratio=decrease,curves=m="${curve}",hue=s=0,format=monob -pix_fmt rgb32 ${output} -y else ffmpeg -i ${file} -frames:v 1 -vf scale=719:-1:force_original_aspect_ratio=decrease,curves=m="${curve}",hue=s=0,format=monob,transpose=1 -pix_fmt rgb32 ${output} -y fi + + if [ $rm_file == true ]; then + rm_file=false + rm ${file} + fi done IFS=$OIFS else @@ -106,9 +119,24 @@ else output="${input%.*}_preprocessed.png" fi + if [[ "${input##*.}" = "pdf" || "${input##*.}" = "PDF" ]] ; then + rm_file=true + old_file=$input + + base_file_name=$(basename "${input%.*}") + input=".tmp_${base_file_name}.png" + + magick $old_file $input + fi + if [ "$(( $(identify -format "%w ${turn} %h" ${input}) ))" = "1" ]; then ffmpeg -i ${input} -frames:v 1 -vf scale=-1:719:force_original_aspect_ratio=decrease,curves=m="${curve}",hue=s=0,format=monob -pix_fmt rgb32 ${output} -y else ffmpeg -i ${input} -frames:v 1 -vf scale=719:-1:force_original_aspect_ratio=decrease,curves=m="${curve}",hue=s=0,format=monob,transpose=1 -pix_fmt rgb32 ${output} -y fi + + if [ $rm_file == true ]; then + rm_file=false + rm ${input} + fi fi