Compare commits

...

10 commits

Author SHA1 Message Date
Rodolphe Breard
0326837a62 Removing trailing spaces. 2015-11-04 20:43:49 +01:00
Rodolphe Breard
1b406e97bd Ignoring vim swapfiles. 2015-11-04 20:43:26 +01:00
Rodolphe Breard
2885143d58 Fixing a size detection bug.
The conditions used to determine whether or not an image have to be
processed depending on its size were boggus. This commit fixes the
issue, images are now processed as they should.
2015-09-12 19:03:38 +02:00
Rodolphe Breard
31bf102452 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.
2015-09-12 18:43:06 +02:00
Rodolphe Breard
973cfabe69 Improving the README.
It's still too simplistic, but the following items have to be here:
 - specifying the vCard version supported ;
 - specifying the requirements ;
 - links to the specifications and useful stuff.
2015-09-05 22:17:49 +02:00
Rodolphe Breard
f77a385101 Ignoring photo URLs.
Photos inserted as an URL instead of being base64 encoded should
not be compressed.
2015-09-05 22:15:31 +02:00
Rodolphe Breard
63ee7ac32d Adding a minimalistic readme. 2015-09-05 21:39:33 +02:00
Rodolphe Breard
555567e321 Ignoring test files. 2015-09-05 21:38:54 +02:00
Rodolphe Breard
188de5661b Removing the useless -V alias. 2015-09-05 21:38:18 +02:00
Rodolphe Breard
decebd46b1 Compressing images using imagemagick. 2015-09-05 21:25:13 +02:00
3 changed files with 64 additions and 17 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
*~ *~
\#* \#*
.\#* .\#*
*.swp
*.vcf

17
README.md Normal file
View file

@ -0,0 +1,17 @@
# VCF Compressor
A simple bash script that compress images inside a vCard 3.0.
## Requirements
* bash
* imagemagick
## Further reading
* [vCard on Wikipedia](https://en.wikipedia.org/wiki/VCard)
* vCard 3.0: [RFC 2425](https://tools.ietf.org/html/rfc2425) and [RFC 2426](https://tools.ietf.org/html/rfc2426)
* vCard 4.0: [RFC 6350](https://tools.ietf.org/html/rfc6350)
* CardDAV: [RFC 6352](https://tools.ietf.org/html/rfc6352)

View file

@ -1,16 +1,16 @@
#!/bin/bash #!/bin/bash
## Copyright (c) 2015 Rodolphe Breard ## Copyright (c) 2015 Rodolphe Breard
## ##
## This program is free software: you can redistribute it and/or modify ## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by ## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or ## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version. ## (at your option) any later version.
## ##
## This program is distributed in the hope that it will be useful, ## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of ## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
## You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>. ## along with this program. If not, see <http://www.gnu.org/licenses/>.
## ##
@ -29,21 +29,46 @@ usage () {
echo "" echo ""
echo "Options:" echo "Options:"
echo " -o, --output" echo " -o, --output"
echo " -v, --verbose" echo " --version"
echo " -V, --version"
echo " -h, --help" echo " -h, --help"
exit "$exit_status" exit "$exit_status"
} }
echo_verbose () { raw_img () {
if [ $verbose -gt 0 ]; then line="$1"
echo "$@"
echo "$line" | cut -d ":" -f2 | base64 -d
}
compress_photo () {
line="$1"
max_width="300"
max_height="300"
prefix=$(echo "$line" | cut -d ":" -f1)
width=$(raw_img "$line" | identify -format '%w' -)
height=$(raw_img "$line" | identify -format '%h' -)
if [ "$width" -gt "$max_width" ] || [ "$height" -gt "$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 () {
line="$1"
echo "$line" | egrep "^PHOTO;" | grep ";ENCODING=b;" >/dev/null 2>&1
if [ $? -eq 0 ]; then
compress_photo "$line"
else
echo "$line"
fi fi
} }
input_file="" input_file=""
output_file="" output_file=""
verbose=0
while :; do while :; do
test $# -gt 0 || break test $# -gt 0 || break
@ -57,11 +82,7 @@ while :; do
usage usage
fi fi
;; ;;
-v|--verbose) --version)
verbose=1
shift
;;
-V|--version)
version version
;; ;;
-h|--help) -h|--help)
@ -79,12 +100,19 @@ while :; do
esac esac
done done
test -z "$input_file" && usage test -z "$input_file" && usage
if [ ! -f "$input_file" ]; then
echo "$input_file: file not found"
exit 1
fi
if [ -z "$output_file" ]; then if [ -z "$output_file" ]; then
dir=$(dirname "$input_file") dir=$(dirname "$input_file")
name=$(basename "$input_file" ".vcf") name=$(basename "$input_file" ".vcf")
output_file="$dir/$name.new.vcf" output_file="$dir/$name.new.vcf"
fi fi
echo "in: $input_file" echo -n > "$output_file"
echo "out: $output_file"
echo_verbose "verbose mode on" while IFS='' read -r line || [[ -n "$line" ]]; do
line=$(process_line "$line")
echo "$line" >> "$output_file"
done < "$input_file"