Likely double pages don't get split anymore

This commit is contained in:
RealStickman 2022-02-13 13:36:49 +01:00
parent 5379685569
commit 82c2ea77b4

View File

@ -27,18 +27,60 @@ for image in "${images[@]}"; do
num=$(echo "$noext" | grep -Eoe [0-9]{3})
# strip leading 0s
num="${num##+(0)}"
# if number is empty (like with 000), set it to 0
[[ -z "${num}" ]] && num=0
if (( $(echo "$ratio > 1" |bc -l) )); then
# crop image in half
convert -crop 50%x100% "$image" "../$out/$noext-%d.jpeg"
# rename the -1, which is the first page to the original name
mv "../$out/$noext-1.jpeg" "../$out/page${num}.jpeg"
# increment image number
((num++))
# rename -0 to original image + 1 name
mv "../$out/$noext-0.jpeg" "../$out/page${num}.jpeg"
# images with horizontal orientation
if (( $(echo "$ratio > 1" | bc -l) )); then
# check whether image should be double or single paged
cropwidth=50
# get image measurements
width=$(identify -format "%w" "$image")
height=$(identify -format "%h" "$image")
left="$(convert "$image" -crop "${cropwidth}"x"${height}"+"$(echo "$width / 2 - $cropwidth" | bc -l)"+0 -resize 1x1\! -format "%[fx:mean]" info:-)"
right="$(convert "$image" -crop ${cropwidth}x${height}+$(echo "$width / 2" | bc -l)+0 -resize 1x1\! -format "%[fx:mean]" info:-)"
# if either left or right are above the threshold, split the image
if (( $(echo "$left > 0.93" | bc -l) )) || (( $(echo "$right > 0.93" | bc -l) )); then
# crop image in half
convert -crop 50%x100% "$image" "../$out/$noext-%d.jpeg"
# rename the -1, which is the first page to the original name
mv "../$out/$noext-1.jpeg" "../$out/page${num}.jpeg"
# increment image number
((num++))
# rename -0 to original image + 1 name
mv "../$out/$noext-0.jpeg" "../$out/page${num}.jpeg"
# copy double pages
else
cp "$image" "../$out/page${num}.jpeg"
fi
# images with vertical orientation
else
# move all other images
mv "$image" "../$out/page${num}.jpeg"
# copy all other images
cp "$image" "../$out/page${num}.jpeg"
fi
done
# find average color in an area
# %[fx:int(255*r+.5)]: color value of R-channel
# %[fx:mean]: overall brightness from 0 to 1
# %[fx:mean.r]: brightness from 0 to 1 for R-channel
#convert page001.jpeg -crop (area width)x(area height)+(x-coord top left)+(y-coord to left) -resize 1x1\! -format "%[fx:int(255*r+.5)],%[fx:int(255*g+.5)],%[fx:int(255*b+.5)]" info:-
#convert page001.jpeg -crop 50x1650+1109+0 -resize 1x1\! -format "%[fx:mean],%[fx:mean.r],%[fx:mean.g],%[fx:mean.b]," info:-
# left
#convert page001.jpeg -crop 50x1650+1109+0 -resize 1x1\! -format "%[fx:mean]" info:-
# right
#convert page001.jpeg -crop 50x1650+1159+0 -resize 1x1\! -format "%[fx:mean]" info:-
# crop image to the area specified
#convert page001.jpeg -crop 100x1650+1109+0 page001-test.jpeg
# one crop left and one crop right
# if either one is over the threshold, we split the image
#convert page001.jpeg -crop (crop width)x(image height)+(half image width - crop width)+0 page001-left.jpeg
#convert page001.jpeg -crop (crop width)x(image height)+(half image width)+0 page001-right.jpeg
# some values
# for split, find lower numbers
# to split: 0.969366
# for not split, find highest numbers
# not split: 0.917692