Sorry it's because the line assigning GPS has been indented, my bad (and a poor way to set IFS anyway) for writing code that must start in column 1!
Replace:
Code:
# Fetch GPS info into array
IFS="
" GPS=( $(jhead $source | grep "GPS ") )
with
Code:
# Fetch GPS info into array
IFS=$'\n' GPS=($(jhead $source | grep "GPS " ))
BTW, To avoid warnings about font not found, you should set FONT= at the top of the program to a pathname contaning your font eg FONT=/usr/share/font/misc/times.ttf or make a font directory in your home dir and copy fonts you might want to try out there FONT=~/fonts/arial.ttf
Last edited by Chubler_XL; 01-06-2011 at 06:46 PM..
This User Gave Thanks to Chubler_XL For This Post:
Chulber_XL, thx for thi sversion. I tried it but all the information is not printed on the pictures. the black frame is too shorl also.
New Script - 2n version
Old Script - 1st version
If fixing is too complicated, I am satisfied with thee first versions, it works fine. How can you modify it in order to execute it on many jpg at the same time.
using this form
Code:
./GPStagtoPic.sh *.jpg
Old version of the script (OK)
Code:
source=$1
target=${1%.jpg}GPS.jpg
# get the image's size, width=$1, length=$2, you need adjust for your image,
# depand the output format of command identify
set -- $(identify $source |awk 'NR==1{split($3,a,"x"); print a[1],a[2]}')
I_WIDTH=$1
I_LENGTH=$2
function maxwidth()
{
MAX_WIDTH=0
while read line
do
INFO=$(convert -size 1025x768 xc:lightblue -font times.ttf -pointsize 18 -fill none -undercolor white -annotate +20+100 "$line" -trim info:)
WIDTH=${INFO##*XC }
WIDTH=${WIDTH%%x*}
[ $WIDTH -gt $MAX_WIDTH ] && MAX_WIDTH=$WIDTH
done
echo $MAX_WIDTH
}
MW=$(jhead $source| grep "GPS " | maxwidth)
let WIDTH=MW+10
HEIGHT=60
convert -size ${WIDTH}x${HEIGHT} xc:black plaque.jpg
composite plaque.jpg -geometry +5+$(( $I_LENGTH - $HEIGHT - 5 )) -dissolve 60 $source $target
CMD=$(jhead $source |grep "GPS " |awk -v width=$1 -v lngth=$2 -v tfile=$target '
NR==1{Latitude=$0}NR==2{Longitude=$0} NR==3{Altitude=$0}
END{
printf "convert -pointsize 18 -font times.ttf -fill white "
printf "-draw \"text 10,%d %c%s%c\" ", lngth-46, 39, Latitude, 39
printf "-draw \"text 10,%d %c%s%c\" ", lngth-28, 39, Longitude, 39
printf "-draw \"text 10,%d %c%s%c\" ", lngth-10, 39, Altitude, 39
printf "%s %s\n", tfile, tfile }')
eval $CMD
Newversion of the script (NOK)
Code:
#!/bin/bash
FONT=times.ttf
FONT_SIZE=18
# Get width or length from image info string
function getwl
{
read WnL
# Get 3rd word
WnL=${WnL#* * }
WnL=${WnL%% *}
# Remove from + to end
WnL=${WnL%%+*}
# Width before 'x' Length after
[ $1 = 'L' ] && echo ${WnL#*x}
[ $1 = 'W' ] && echo ${WnL%x*}
}
function process_image
{
source=$1
target=${1%.jpg}GPS.jpg
I_HEIGHT=$(identify $source | getwl L)
# Fetch GPS info into array
IFS="
" GPS=( $(jhead $source | grep "GPS ") )
MW=0
for line in "${GPS[0]}" "${GPS[1]}" "${GPS[2]}"
do
WIDTH=$(convert -size 1025x768 xc:lightblue -font $FONT \
-pointsize $FONT_SIZE -fill none -undercolor white \
-annotate +20+100 "$line" -trim info: | getwl W)
[ $WIDTH -gt $MW ] && MW=$WIDTH
done
let WIDTH=MW+10
let P_HEIGHT=FONT_HEIGHT*3+6
convert -size ${WIDTH}x${P_HEIGHT} xc:black plaque.jpg
composite plaque.jpg -geometry +5+$(( $I_HEIGHT - $P_HEIGHT - 5 )) \
-dissolve 60 $source $target
convert -pointsize $FONT_SIZE -font $FONT -fill white \
-draw "text 10,$((I_HEIGHT - FONT_HEIGHT*7/3 - 8)) \"${GPS[0]}\"" \
-draw "text 10,$((I_HEIGHT - FONT_HEIGHT*4/3 - 8)) \"${GPS[1]}\"" \
-draw "text 10,$((I_HEIGHT - FONT_HEIGHT*1/3 - 8)) \"${GPS[2]}\"" \
$target $target
}
FONT_HEIGHT=$(convert -size 1025x768 xc:lightblue -font $FONT \
-pointsize $FONT_SIZE -fill none -undercolor white \
-annotate +20+100 "Testing" -trim info: | getwl L)
for file in $@
do
process_image $file
done
Thx,
Last edited by flash80; 01-08-2011 at 05:48 PM..
Reason: used PHP tags instead of COD
I need a hint about gvfsd-metadata using mate on bsd. Or dual-core cpu, quad-core cpu ore an old laptop single core, the gvfsd is an obstacle and does not accelerate anything, vice versa, it slows down many processes, coming from gnome. So someone can give me a hint how to wipe it out for good? I... (1 Reply)
Hi guys,
I would like to ask your opinion about my theory, how to fix my broken LVM without risking any data loss.
I use Archlinux at home. I just love this distro, even it gives me a lots of work (particularly after system updates).
Basic system spec:
AMD FX(tm)-6100 Six-Core Processor... (1 Reply)
Hi, Dear all:
One question ! ^_^
I'm using bash under Ubuntu 9.10.
My question is not to rename all ".JPG" files to ".jpg" in a single folder, but to rename all ".JPG" files to ".jpg" in all subfolders.
To rename all ".JPG" to ".jpg" in a single folder,
for x in *.JPG; do mv "$x"... (7 Replies)
Hi,
my application (actually library) indexes a file of many GB producing tables (arrays of offset and length of the data indexed) for later reuse. The tables produced are pretty big too, so big that I ran out of memory in my process (3GB limit), when indexing more than 8GB of file or so.... (9 Replies)
Is there any possible way to print the contents of a directory to a .jpg file? I have a list of thumbnails (e-books) which I want to share (+500) but I don't know how to make this.
I would appreciate a lot any comments regarding this issue. (4 Replies)