Sponsored Content
Full Discussion: print metadata to jpg
Top Forums Shell Programming and Scripting print metadata to jpg Post 302485630 by Chubler_XL on Wednesday 5th of January 2011 06:46:41 PM
Old 01-05-2011
If your going to process a few images it is worth removing the calls to awk and using bash arrays/string processing instead.

Here is a version that defines font and size at to so you can trial different fonts/point sizes:

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

This User 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
load_dat_font(3alleg4)						  Allegro manual					    load_dat_font(3alleg4)

NAME
load_dat_font - Loads a FONT from an Allegro datafile. SYNOPSIS
#include <allegro.h> FONT *load_dat_font(const char *filename, RGB *pal, void *param) DESCRIPTION
Loads a FONT from an Allegro datafile. You can set param parameter to point to an array that holds two strings that identify the font and the palette in the datafile by name. The first string in this list is the name of the font. You can pass NULL here to just load the first font found in the datafile. The second string can be used to specify the name of the palette associated with the font. This is only returned if the pal parameter is not NULL. If you pass NULL for the name of the palette, the last palette found before the font was found is returned. You can also pass NULL for param, which is treated as if you had passed NULL for both strings separately. In this case, the function will simply load the first font it finds from the datafile and the palette that precedes it. For example, suppose you have a datafile named `fonts.dat' with the following contents: FONT FONT_1_DATA FONT FONT_2_DATA FONT FONT_3_DATA PAL FONT_1_PALETTE PAL FONT_2_PALETTE Then the following code will load FONT_1_DATA as a FONT and return FONT_1_PALETTE as the palette: FONT *f; PALETTE pal; char *names[] = { "FONT_1_DATA", "FONT_1_PALETTE" } f = load_dat_font("fonts.dat", pal, names); If instead you want to load the second font, FONT_2, from the datafile, you would use: FONT *f; PALETTE pal; char *names[] = { "FONT_2_DATA", "FONT_2_PALETTE" } f = load_dat_font("fonts.dat", pal, names); If you want to load the third font, but not bother with a palette, use: FONT *f; char *names[] = { "FONT_3_DATA", NULL } f = load_dat_font("fonts.dat", NULL, names); RETURN VALUE
Returns a pointer to the font or NULL on error. Remember that you are responsible for destroying the font when you are finished with it to avoid memory leaks. SEE ALSO
register_font_file_type(3alleg4), load_font(3alleg4) Allegro version 4.4.2 load_dat_font(3alleg4)
All times are GMT -4. The time now is 11:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy