Page 1 of 2
Annotating photos with metadata -SOLVED
Posted: 2017-04-04T07:11:55-07:00
by schievelbein
I am a genealogist and have thousands of photos that I want to annotate and update at any given time.
I want to maintain the integrity of the original photos, so I am splicing an annotation area to the bottom, so if I need to update the annotation, I can simply trim off the old and add another. The annotations are coming from the metadata that I am maintaining using gThumb in Linux, not that it should matter. The problem is that some of the photos have a LOT of people and the descriptions can be very long. I do not want the font to get too small, so I need word wrap. I thought that CAPTION with its word wrap might be able to help, but I cannot see to get it to work. The second issue that I might have is whether the spliced area will be tall enough. If I could know how many lines I was going to have, I could change my splice to be a multiple of the lines. My first Convert works, but the second does not. Thank you for any suggestions.
Code: Select all
read cwidth csplice cfont cdate ctime cdesc <<< $( identify -format "%w %[fx:h*.05] %[fx:h*.04] %[EXIF:DateTimeOriginal] %[IPTC:2:120]" $1 )
convert $1 -gravity South -background Black -pointsize $cfont -fill White -splice 0x${csplice} -annotate +0+0 "$cdesc" annotated_$1
#convert $1 -gravity South -background Black -pointsize $cfont -fill White -splice 0x${csplice} -size $cwidth caption:"$cdesc" annotated_$1
Re: Annotating phots
Posted: 2017-04-04T07:37:38-07:00
by Bonzo
Out of interest you may be able to use less commands with Imagemagick version 7 - what version are you using?
Re: Annotating photos with metadata
Posted: 2017-04-04T08:36:08-07:00
by schievelbein
I am currently using 6.7.7 on Linux Ubuntu, I will look into updating.
What suggestions do you have if I switch to Ver 7?
Re: Annotating photos with metadata
Posted: 2017-04-04T09:19:23-07:00
by Bonzo
You should be able to use the fx calculations and EXIF data directly in the convert line.
For instance:
Code: Select all
magick "input.jpg" -gravity South -background Black -pointsize 10 -fill White -splice 0x%[fx:h*.04] -annotate +0+0 %[EXIF:DateTimeOriginal] "annotated.jpg"
Re: Annotating photos with metadata
Posted: 2017-04-04T12:10:00-07:00
by Bonzo
I was thinking about something along the lines of this but it will not work with caption as I get a geometry error:
magick: geometry does not contain image `input.jpg' @ warning/attribute.c/GetImageBoundingBox/240.
Here is the code with an -annotate for testing:
Code: Select all
magick "input.jpg" ( -clone 0 -fill Black -colorize 100 -gravity north -pointsize 20 -fill White -annotate +0+0 "This is a very very long line and I will repeat some more blurb to make it a bit longer and longer" -trim ) -append "annotated.jpg"
It reads in the original image, copies it and changes it to black. Adds the white text to the now black copy; trims it down to the text size and joins the two images. This process would probably need to add an -extent or similar to get the width back to the size of the original.
Re: Annotating photos with metadata
Posted: 2017-04-04T12:50:00-07:00
by fmw42
Did you try adding +repage after the -trim?
Re: Annotating photos with metadata
Posted: 2017-04-04T12:52:16-07:00
by Bonzo
This also sort of works but the text wraps on a very narrow column !
Code: Select all
magick "input.jpg" ( -clone 0 -size %[fx:w]x%[fx:h] -delete 0 -background black -gravity center -pointsize 20 -fill White caption:"This is a very very long line and I will repeat some more blurb to make it a bit longer and longer" -trim ) -append "annotated.jpg"
Code modified as per fmw42's post below.
Did you try adding +repage after the -trim?
No I didn't fmw42 but just tried and get the same geometry error
Re: Annotating photos with metadata
Posted: 2017-04-04T12:56:42-07:00
by fmw42
Re: Annotating photos with metadata
Posted: 2017-04-04T12:57:58-07:00
by Bonzo
Thank you fmw42 that seems to have fixed it.
It looks to me like the caption needs a size defined to work.
Re: Annotating photos with metadata
Posted: 2017-04-04T13:30:39-07:00
by schievelbein
Thank you for the suggestions.
I have changed my code to read as follows:
Code: Select all
convert "input.jpg" ( -clone 0 -size %[fx:w]x%[fx:h] -delete 0 -background black -gravity center -pointsize 20 -fill White caption:"This is a very very long line and I will repeat some more blurb to make it a bit longer and longer" -trim ) -append "annotated.jpg"
I am getting a syntax error and cannot figure it out.
Any recommendation would be greatly appreciated.
Re: Annotating photos with metadata
Posted: 2017-04-04T13:42:12-07:00
by Bonzo
My example above worked with caption and text but on testing fails with the %[EXIF:DateTimeOriginal] you may have to go back to reading that data into a variable first.
Did you try my example code with one of your images as it seems to do what you want except for the EXIF and IPTC data?
Re: Annotating photos with metadata
Posted: 2017-04-04T13:44:51-07:00
by schievelbein
I tried with a couple of my images and I receive the following:
./annotate: line 8: syntax error near unexpected token `('
./annotate: line 8: `convert "input.jpg" ( -clone 0 -size %[fx:w]x%[fx:h] -delete 0 -background black -gravity center -pointsize 20 -fill White caption:"This is a very very long line and I will repeat some more blurb to make it a bit longer and longer" -trim ) -append "annotated.jpg"'
Thank you very much for your help.
Re: Annotating photos with metadata
Posted: 2017-04-04T13:55:15-07:00
by Bonzo
On windows you need ( ) and I think on Linux ( and mac? ) you need to use \( \) try that.
Re: Annotating photos with metadata
Posted: 2017-04-04T15:02:19-07:00
by schievelbein
Thank you very much for the suggestions. The CAPTION is working as advertised, however, now, I am having trouble with the parameters.
I have tried many variation and cannot get the $cdesc and $cw or any of the other parameters to work. Any suggestion on being able to pass these parameters to Size and Caption would be appreciated.
Code: Select all
read cw ch cs cf cd ct cdesc <<< $( identify -format "%w %h %[fx:h*.05] %[fx:h*.04] %[EXIF:DateTimeOriginal] %[IPTC:2:120]" $1 )
convert "input.jpg" \( -clone 0 -size 1200 -delete 0 -background black -gravity center -pointsize 20 -fill White caption:"This is a very very long line and I will repeat some more blurb to make it a bit longer and longer This is a very very long line and I will repeat some more blurb to make it a bit longer and longer This is a very very long line and I will repeat some more blurb to make it a bit longer and longer" -trim \) -append "annotated.jpg"
Re: Annotating photos with metadata
Posted: 2017-04-04T15:41:24-07:00
by fmw42
Perhaps your $1 is not getting resolve. Try using an actual image as a test.
What does your first command have to do with the subsequent convert command. I see no variables being passed.