Do not compress small images.

Before this commit, every images were reprocessed all of the time.
Because the address book may be re-compressed when new pictures are
added, we want to process them and not reprocess the previous ones.
This commit include a size detection so images below the size limit
are not processed.
This commit is contained in:
Rodolphe Breard 2015-09-12 18:43:06 +02:00
parent 973cfabe69
commit 31bf102452

View file

@ -34,12 +34,26 @@ usage () {
exit "$exit_status" exit "$exit_status"
} }
compress_photo () { raw_img () {
line="$1" line="$1"
echo "$line" | cut -d ":" -f2 | base64 -d
}
compress_photo () {
line="$1"
max_width="300"
max_height="300"
prefix=$(echo "$line" | cut -d ":" -f1) prefix=$(echo "$line" | cut -d ":" -f1)
picture=$(echo "$line" | cut -d ":" -f2 | base64 -d | convert "-" -quality 50 -resize "300x300>" "-" | base64 -w0) width=$(raw_img "$line" | identify -format '%w' -)
echo "$prefix:$picture" height=$(raw_img "$line" | identify -format '%h' -)
if [ "$width" -le "$max_width" ] && [ "$height" -le "$max_height" ] ; then
picture=$(raw_img "$line" | convert "-" -quality 50 -resize "${max_width}x${max_height}>" "-" | base64 -w0)
echo "$prefix:$picture"
else
echo "$line"
fi
} }
process_line () { process_line () {