-
-
Save mattak/1129353 to your computer and use it in GitHub Desktop.
embed jpeg bounding box information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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