Likely double pages don't get split anymore
This commit is contained in:
parent
5379685569
commit
82c2ea77b4
@ -27,8 +27,19 @@ for image in "${images[@]}"; do
|
|||||||
num=$(echo "$noext" | grep -Eoe [0-9]{3})
|
num=$(echo "$noext" | grep -Eoe [0-9]{3})
|
||||||
# strip leading 0s
|
# strip leading 0s
|
||||||
num="${num##+(0)}"
|
num="${num##+(0)}"
|
||||||
|
# if number is empty (like with 000), set it to 0
|
||||||
[[ -z "${num}" ]] && num=0
|
[[ -z "${num}" ]] && num=0
|
||||||
if (( $(echo "$ratio > 1" |bc -l) )); then
|
# 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
|
# crop image in half
|
||||||
convert -crop 50%x100% "$image" "../$out/$noext-%d.jpeg"
|
convert -crop 50%x100% "$image" "../$out/$noext-%d.jpeg"
|
||||||
# rename the -1, which is the first page to the original name
|
# rename the -1, which is the first page to the original name
|
||||||
@ -37,8 +48,39 @@ for image in "${images[@]}"; do
|
|||||||
((num++))
|
((num++))
|
||||||
# rename -0 to original image + 1 name
|
# rename -0 to original image + 1 name
|
||||||
mv "../$out/$noext-0.jpeg" "../$out/page${num}.jpeg"
|
mv "../$out/$noext-0.jpeg" "../$out/page${num}.jpeg"
|
||||||
|
# copy double pages
|
||||||
else
|
else
|
||||||
# move all other images
|
cp "$image" "../$out/page${num}.jpeg"
|
||||||
mv "$image" "../$out/page${num}.jpeg"
|
fi
|
||||||
|
# images with vertical orientation
|
||||||
|
else
|
||||||
|
# copy all other images
|
||||||
|
cp "$image" "../$out/page${num}.jpeg"
|
||||||
fi
|
fi
|
||||||
done
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user