Page 1 of 1

PAID: Extract copyright from comment and annotate image

Posted: 2017-08-11T12:56:28-07:00
by centesimiae
I know I can read the copyright in the comments property, but is there a single command to extract the comment from the image metadata and put in the lower right hand side of the image?

Re: PAID: Extract copyright from comment and annotate image

Posted: 2017-08-11T13:04:53-07:00
by fmw42
What is your IM version and platform?

In IM 6 on unix, you could do

Code: Select all

comment=`convert image -format "%c" info:`
convert image -fill black -pointsize 24 -font arial -gravity southeast -annotate +0+0 "$comment" result

In IM 7 (unix or windows), you can do

Code: Select all

magick image -fill black -pointsize 24 -font arial -gravity southeast -annotate +0+0 "%[comment]" result
Change the pint-size and font as desired. If you font is not in your type.xml file, you can use the path2/fontname.ttf in place of just the font name.

Re: PAID: Extract copyright from comment and annotate image

Posted: 2017-08-14T14:19:16-07:00
by glennrp
This does not seem to work with a PNG image that contains a tEXt chunk with copright. The copyright
line does show up in the output of identify -verbose as a Copyright property.

Code: Select all

Properties:
    Copyright: � 2013,2015 John Cunningham Bowler
    date:create: 2017-08-14T17:12:35-04:00
but does not show up in the info:

So I suppose we have a bug on our hands, in both IM6 and IM7.

Re: PAID: Extract copyright from comment and annotate image

Posted: 2017-08-14T18:43:51-07:00
by fmw42
No, you just said the "comment field". There is a comment field in IM that is unrelated to PNG chucks. That is what I told you how to get. I do not know how to access PNG chunk. For that you need help from the IM PNG developer, glennrp.

Re: PAID: Extract copyright from comment and annotate image

Posted: 2017-08-14T23:52:51-07:00
by snibgo
The copyright notice might appear in a number of places. Cameras put it in an exif field, so we can write it into the image like this:

Code: Select all

convert aga_3364.jpg -resize 600x600 -pointsize 25 -gravity SouthEast -annotate +0+0 %[EXIF:Copyright] x.png
(In v7, use "magick" instead of "convert".)

From my camera (Nikon D800) the copyright notice is padded on the right with spaces, so the text doesn't appear on the right in the output image. We want to strip the trailing spaces. IM doesn't contain string-handling functions, so we have to do that outside IM. For example, Windows CMD syntax, using sed:

Code: Select all

for /F "usebackq tokens=*" %L in (`convert aga_3364.jpg -format %[EXIF:Copyright] info:`) do set COPYR=%L

for /F "usebackq tokens=*" %L in (`echo %COPYR% ^| sed -e 's/[ \t]*$//'`) do set COPY2=%L

convert aga_3364.jpg -resize 600x600 -pointsize 25 -gravity SouthEast -annotate +0+0 "%COPY2%" x.png