Skip to content

Instantly share code, notes, and snippets.

@mattak
Created August 6, 2011 13:49
Show Gist options
  • Save mattak/1129353 to your computer and use it in GitHub Desktop.
Save mattak/1129353 to your computer and use it in GitHub Desktop.
embed jpeg bounding box information
#!/bin/sh
# -*- encoding:utf-8 -*-
exiftool=`which exiftool`
# is exif tool already installed?
if [ -z $exiftool ]; then
echo "please install exiftool."
echo "sudo apt-get install libimage-exiftool-perl"
exit 1
fi
# usage check
if [ $# -lt 1 ]; then
echo "usage: input_jpeg [bound box value]"
echo " ex1. extract bounding box"
echo " ./bbox sample.jpg"
echo " ex2. embed bounding box"
echo " ./bbox sample.jpg 0:0:640:480 10:10:400:300"
exit 1
fi
jpg=$1
original="$1_original"
if [ $# -eq 1 ]; then
exiftool $jpg | while read line; do
if echo "$line" | perl -ne'exit 1 unless /User\s*Comment\s*/i'; then
line=`echo "$line" | sed "s/User\s*Comment\s*:\s*\(\S\)/\1/i"`
echo "$line" | perl -nle'split"[ \t]+";print join("\t",split(":"))for @_'
fi
done
else
boxes=`echo "$*"| sed 's/^\s*\S\+\s\+\(\S\)/\1/'`
exiftool -UserComment="$boxes" $jpg
# tmporary file remove
if [ -e $original ]; then
rm $original
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment