Sponsored Content
Full Discussion: print metadata to jpg
Top Forums Shell Programming and Scripting print metadata to jpg Post 302484981 by Chubler_XL on Tuesday 4th of January 2011 12:35:12 AM
Old 01-04-2011
Looks like there were a couple of slight issues with the solution posted:

length is an awk function and should be used as a variable name
image magic draw function requires text x,y 'string'

Adjusted script to correct these issues:

Code:
source=source.jpg
target=target.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]}')   
 
cat jhead |grep "GPS " |awk -v width=$1 -v lngth=$2 -v sfile=$source -v tfile=$target '
NR==1{Latitude=$0}NR==2{Longitude=$2} NR==3{Altitude=$0}
END{
    printf "convert -pointsize 18 -font times.ttf -fill white "
   printf "-stroke black -strokewidth 1 "
    printf "-draw \"text 10,%d %c%s%c\" ", lngth-72, 39, Latitude, 39
    printf "-draw \"text 10,%d %c%s%c\" ", lngth-54, 39, Longitude, 39
    printf "-draw \"text 10,%d %c%s%c\" ", lngth-36, 39, Altitude, 39
    printf "%s %s\n", sfile, tfile }'

Other things to consider: the black stroke around the text looks really poor with my testing images and you may want to try without the stroke like (remove line is green above). I always like using a gamma adjust in a rectangle where the text is to go (say 0.2 gamma with white text), this tends to help the text stand out from the background.

You would need to play around with imagemagic to measure the size of the text and darken a rectangle where it is to go.

---------- Post updated at 03:35 PM ---------- Previous update was at 01:24 PM ----------

I've had a go at creating a dark plaque sized from the GPS text. This should get you going, but it could be tweaked more.

Your GPS text may always be a consistent width and you could just use a standard image for the plaque (just get rid of the maxwidth function and the convert command that created the black plauque.jpg images:

Code:
source=source.jpg
target=target.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=$(cat jhead | 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=$(cat jhead |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

Here is a pretty light image (mainly white where the text is to appear) and I think it is still quite readable at 60%:

Image
These 2 Users Gave Thanks to Chubler_XL For This Post:
 

5 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Print the content of a directory in jpg file

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)
Discussion started by: agasamapetilon
4 Replies

2. Programming

Best way to dump metadata to file: when and by who?

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)
Discussion started by: emitrax
9 Replies

3. Shell Programming and Scripting

Rename all ".JPG" files to ".jpg" under all subfolders...

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)
Discussion started by: jiapei100
7 Replies

4. UNIX for Advanced & Expert Users

LVM - restore metadata on other disk

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)
Discussion started by: lyynxxx
1 Replies

5. UNIX and Linux Applications

About gvfsd-metadata

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)
Discussion started by: 1in10
1 Replies
All times are GMT -4. The time now is 09:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy