From 31bf10245282d24870ddb170f653dd1c12c5887d Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sat, 12 Sep 2015 18:43:06 +0200 Subject: [PATCH] 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. --- vcf_compressor.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/vcf_compressor.sh b/vcf_compressor.sh index 1634ba4..fa2f16d 100755 --- a/vcf_compressor.sh +++ b/vcf_compressor.sh @@ -34,12 +34,26 @@ usage () { exit "$exit_status" } -compress_photo () { +raw_img () { 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) - picture=$(echo "$line" | cut -d ":" -f2 | base64 -d | convert "-" -quality 50 -resize "300x300>" "-" | base64 -w0) - echo "$prefix:$picture" + width=$(raw_img "$line" | identify -format '%w' -) + 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 () {