Page 1 of 2
Writing IPTC field data into a border
Posted: 2010-05-07T07:50:39-07:00
by adrianlambert
Hi there, first post...
I want to create a digital frame with the data from several IPTC fields displayed on the frame, Caption, date, copyright info etc. I've used LR/mogrify with lightroom to do this but want to move away from lightroom and the one last bind is that I can't find a solution to this problem. Before I get stuck into the user resources I wanted to pose the simple question, is this possible with Imagemagick? I'm working on macs and would then like to be able to make this run as a folder action or some kind of droplet. Any thoughts on this?
Re: Writing IPTC field data into a border
Posted: 2010-05-07T08:55:42-07:00
by snibgo
Yes, it probably is possible. Your best bet is to post the URL to a sample image and tell us if you are on Unix/Windows/Mac/whatever, and someone may chip in a script.
Re: Writing IPTC field data into a border
Posted: 2010-05-08T06:43:02-07:00
by adrianlambert
Thanks, I'll have a go myself first though just for fun...
I've got to first base and got a border that I like. As for the IPTC, this looks tricky.
Could someone let me know if my thinking is sound... Would I read the metadata from the field that I want to annotate, and write it into a text file then use the contents of that file as the source of the annotation?
Re: Writing IPTC field data into a border
Posted: 2010-05-08T07:26:44-07:00
by snibgo
Thanks, I'll have a go myself first though just for fun...
That's the spirit!
You could use a text file, which would be a good way of finding out what IPTC info a file contains. For production use, you could set environment variables, eg COPYRIGHT for the copyright string, and use these variables in "annotate" or "caption".
See
http://www.imagemagick.org/script/sitemap.php for general docs, and
viewtopic.php?f=1&t=15825 for a (Windows) example of environment variables.
Re: Writing IPTC field data into a border
Posted: 2010-05-08T07:52:14-07:00
by Bonzo
You need to get your EXIF data into a variable and it may need some formatting to get what you want:
Image Magick returns the F number in the format of 700/100 or 40/10
Image Magick returns the shutter speed in the format of 810/100
Calculate the speed in seconds using the power of 2 and save it in the shutterspeed variable
I pressume IPTC data is similar to EXIF ?
Anyway you can see the full list of data ImageMagick can find using:
Re: Writing IPTC field data into a border
Posted: 2010-05-08T18:40:49-07:00
by anthony
The second example in...
http://www.imagemagick.org/Usage/thumbnails/#labels
may be of help. Yes it is complex, but it is extracting the text from one image for generating another 'overlay image' which is then heavily processed. However it should be something like what you are after.
Re: Writing IPTC field data into a border
Posted: 2010-05-08T21:54:15-07:00
by adrianlambert
Thanks fellas.
I'm going for function over form so I'm thinking a bunch of reads of about 8 different IPTC fields and 1 Exif field into variables that can then be compiled into an annotate command might be the way to go. I might be able to do this as a shell script or automator action (mac) then turn it into a droplet for ease of use.
The text in the border at the bottom of the image will just be made up of delimiters and field titles followed by the field variables.
Here's an example of what I currently have.
http://goo.gl/6QeU
I'm hoping to get pretty much the same result. (The photoshop script, written by Russell Brown that does this no longer works with Photoshop CS5 - rather than patch it up which is what I did in the first place I'm hoping to write my own that isn't dependent on a Photoshop)
Re: Writing IPTC field data into a border
Posted: 2010-05-08T23:14:01-07:00
by fmw42
in unix, you can script this by extracting each IPTC field as a variable as follows
field1=`convert image -format "%[IPTC:dataset:record]" info:`
then you can use -annotate or caption: to write all of the variables into the image.
see
http://www.imagemagick.org/script/escape.php and
http://www.imagemagick.org/Usage/text/
Re: Writing IPTC field data into a border
Posted: 2010-05-08T23:21:39-07:00
by snibgo
Yes, that should be straight-forward. "caption:" might be best, as it does word-wrapping for you.
For the IPTC and EXIF fields available, see
http://www.imagemagick.org/script/escape.php
For text, see
http://www.imagemagick.org/Usage/text/
Re: Writing IPTC field data into a border
Posted: 2010-05-09T01:25:41-07:00
by anthony
Also see IM Examples, Annotating Images, Annotating Above and Below..
http://www.imagemagick.org/Usage/annotating/#anno_below
Re: Writing IPTC field data into a border
Posted: 2010-05-09T05:03:50-07:00
by adrianlambert
fmw42 wrote:
in unix, you can script this by extracting each IPTC field as a variable as follows
field1=`convert image -format "%[IPTC:dataset:record]" info:`
Thanks, this will likely be the basis of what I'm going to do.
snibgo wrote:
Yes, that should be straight-forward. "caption:" might be best, as it does word-wrapping for you.
Great tip, thanks. I'd scanned the relevant options but hadn't picked that up yet. Looks like "caption" it is.
Re: Writing IPTC field data into a border
Posted: 2010-05-09T10:38:00-07:00
by adrianlambert
Thanks to everyone for the invaluable help, here it is so far...
Code: Select all
#!/bin/sh
# Set variable for the current filename
CURRENTIMAGE=./EvaPassport.jpg
# Set variables for the IPTC EXIF and ImageMagick fields
COPYRIGHTNOTICE=`convert $CURRENTIMAGE -format "%[IPTC:2:116]" info:`
FILENAME=`convert $CURRENTIMAGE -format "%t" info:`
CAPTION=`convert $CURRENTIMAGE -format "%[IPTC:2:120]" info:`
CITY=`convert $CURRENTIMAGE -format "%[IPTC:2:90]" info:`
STATEPROVINCE=`convert $CURRENTIMAGE -format "%[IPTC:2:95]" info:`
COLOURPROFILE=`convert $CURRENTIMAGE -format "%r]" info:`
SPECIALINSTRUCTIONS=`convert $CURRENTIMAGE -format "%[IPTC:2:40]" info:`
JOBIDENTIFIER=`convert $CURRENTIMAGE -format "%[IPTC:2:103]" info:`
IMAGEWIDTH=`convert $CURRENTIMAGE -format "%w" info:`
IMAGEHEIGHT=`convert $CURRENTIMAGE -format "%h" info:`
CAPTIONHEIGHT=$[$IMAGEHEIGHT / 10]
CAPTIONSIZE=$IMAGEWIDTH"x"$CAPTIONHEIGHT
echo imagewidth is $IMAGEWIDTH
echo imageheight is $IMAGEHEIGHT
echo captionheight is $CAPTIONHEIGHT
echo captionsize is $CAPTIONSIZE
# print out a test caption based on specific text combined with the returned variables (works except where do I get the colour profile name)
#echo 'Please archive original file with border. A path is embedded to remove the border | '$COPYRIGHTNOTICE' | '$FILENAME' | Caption: '$CAPTION' | '$CITY' | '$STATEPROVINCE' | '$COLOURPROFILE' | Usage Terms: '$SPECIALINSTRUCTIONS' | Licensee: '$JOBIDENTIFIER |
#create a simple border at the bottom only (Works)
convert $CURRENTIMAGE -gravity North -background grey -extent 100x105% $CURRENTIMAGE
echo 'Please archive original file with border. A path is embedded to remove the border | '$COPYRIGHTNOTICE' | '$FILENAME' | Caption: '$CAPTION' | '$CITY' | '$STATEPROVINCE' | '$COLOURPROFILE' | Usage Terms: '$SPECIALINSTRUCTIONS' | Licensee: '$JOBIDENTIFIER > caption.txt
convert -background grey -font Arial-Narrow-Bold -gravity Center -fill grey10 -size $CAPTIONSIZE caption:@caption.txt caption.jpg
composite -gravity South caption.jpg $CURRENTIMAGE $CURRENTIMAGE
rm caption.txt
rm caption.jpg
Things I still want to achieve are finding a way to write the colour profile into the border. At the moment I get a result that says "DirectClassRGB]". What i wanted to see was "Adobe RGB (1998)". Also the textbox is cropping into the image slightly... too late in the evening to figure that out now though. The one other thing is how to get the CURRENTIMAGE to be dynamic.
Would love any feedback or advice as this is the first scripting I've ever tried.
Re: Writing IPTC field data into a border
Posted: 2010-05-09T10:54:21-07:00
by snibgo
Good stuff. You can get the ICC profile name from "identify -verbose in.jpg". Look for the line after "Profile-icc". There may be a smarter way to get this.
Re: Writing IPTC field data into a border
Posted: 2010-05-09T19:07:55-07:00
by adrianlambert
snibgo wrote:You can get the ICC profile name from "identify -verbose in.jpg". Look for the line after "Profile-icc
Thanks.
I can't see a simple way to ensure the right text would pass through.
I might have to drop that field.
Re: Writing IPTC field data into a border
Posted: 2010-05-09T23:12:18-07:00
by adrianlambert
snibgo wrote:You can get the ICC profile name from "identify -verbose in.jpg". Look for the line after "Profile-icc".
Thanks snibgo, that fixed it for me after a bit more reading...
I also got the caption to sit better without cropping the image.
If anyone wants to try this that would be much appreciated.
to run it, in a terminal window type ./MetaCaptionIM.sh /PATHTO/FILENAME.XXX
It overwrites the inputted image so back it up first.
I'd like to do more to make it more useable as I mentioned before so that it could run a batch of images.
Any advice?
Thanks for the help, I've over the moon just being able to figure this much out. Great forum.
Code: Select all
#!/bin/sh
# This is a script written with help by Adrian Lambert to unceremoniously caption an image file with a set of matadata fields using ImageMagick.
# Set variable for the current filename to the first argument in the command line.
CURRENTIMAGE=$1
# Set caption variables for the IPTC EXIF and ImageMagick fields.
FILENAME=`convert $CURRENTIMAGE -format "%t" info:`
COPYRIGHTNOTICE=`convert $CURRENTIMAGE -format "%[IPTC:2:116]" info:`
CAPTION=`convert $CURRENTIMAGE -format "%[IPTC:2:120]" info:`
CITY=`convert $CURRENTIMAGE -format "%[IPTC:2:90]" info:`
STATEPROVINCE=`convert $CURRENTIMAGE -format "%[IPTC:2:95]" info:`
SPECIALINSTRUCTIONS=`convert $CURRENTIMAGE -format "%[IPTC:2:40]" info:`
JOBIDENTIFIER=`convert $CURRENTIMAGE -format "%[IPTC:2:103]" info:`
# Set the Colourspace name in a simple format from ImageMagick
COLOURPROFILE=`identify -verbose $CURRENTIMAGE | grep -E "Grey|RGB|sRGB|CMYK" | grep -v Colorspace`
# Get the image width and height.
IMAGEWIDTH=`convert $CURRENTIMAGE -format "%w" info:`
IMAGEHEIGHT=`convert $CURRENTIMAGE -format "%h" info:`
# Set caption height to 5% of the overall image height.
CAPTIONHEIGHT=$[$IMAGEHEIGHT / 20]
# Set the caption area to the width of the input image by the captionheight
CAPTIONSIZE=$IMAGEWIDTH"x"$CAPTIONHEIGHT
# Create a simple border at the bottom only
convert $CURRENTIMAGE -gravity North -background grey -extent 100x105% $CURRENTIMAGE
# Write the caption to a temporary text file.
echo 'Please archive original file with border. A path is embedded to remove the border | '$COPYRIGHTNOTICE' | '$FILENAME' | Caption: '$CAPTION' | '$CITY' | '$STATEPROVINCE' | '$COLOURPROFILE' | Usage Terms: '$SPECIALINSTRUCTIONS' | Licensee: '$JOBIDENTIFIER > caption.txt
# Create an image from the temporary text file as a temporary image file.
convert -background grey -font Arial-Narrow-Bold -gravity Center -fill grey10 -size $CAPTIONSIZE caption:@caption.txt caption.jpg
# Create a composite of the input image with it's caption
composite -gravity South caption.jpg $CURRENTIMAGE $CURRENTIMAGE
# Tidy up temp files.
rm caption.txt
rm caption.jpg