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:
parent
973cfabe69
commit
31bf102452
1 changed files with 17 additions and 3 deletions
|
@ -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)
|
||||
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 () {
|
||||
|
|
Reference in a new issue