Compressing images using imagemagick.

This commit is contained in:
Rodolphe Breard 2015-09-05 21:25:13 +02:00
parent 250dc2d0bf
commit decebd46b1

View file

@ -29,21 +29,32 @@ usage () {
echo "" echo ""
echo "Options:" echo "Options:"
echo " -o, --output" echo " -o, --output"
echo " -v, --verbose"
echo " -V, --version" echo " -V, --version"
echo " -h, --help" echo " -h, --help"
exit "$exit_status" exit "$exit_status"
} }
echo_verbose () { compress_photo () {
if [ $verbose -gt 0 ]; then line="$1"
echo "$@"
prefix=$(echo "$line" | cut -d ":" -f1)
picture=$(echo "$line" | cut -d ":" -f2 | base64 -d | convert "-" -quality 50 -resize "300x300>" "-" | base64 -w0)
echo "$prefix:$picture"
}
process_line () {
line="$1"
echo "$line" | egrep "^PHOTO;" >/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,10 +68,6 @@ while :; do
usage usage
fi fi
;; ;;
-v|--verbose)
verbose=1
shift
;;
-V|--version) -V|--version)
version version
;; ;;
@ -79,12 +86,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"