Improving my "caption:" code

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Anton79
Posts: 2
Joined: 2019-09-20T22:44:27-07:00
Authentication code: 1152

Improving my "caption:" code

Post by Anton79 »

Hi there,
I'm not a great whizz with linux scripting etc.
I'm running ImageMagick 6.9.10-14 Q16 x86_64 20181023 as this is the version my Ubuntu comes with and I got a bit lost with the manual update instructions.

I love the text flow abilities of the "caption:" option but want the caption to be on a new blank border so I can see the full original image.
I've got a solution working, its not pretty though. Perhaps someone can suggest a performance improvement using the ImageMagick 6.9.10-14 ?
Here is my code. As you see, I run convert twice which I'm guessing isn't the best way of doing things:


height=`identify -format %h "$fileorig"`
spl=$(expr $height / 10) ; # controls height of the box at the bottom

convert "$fileorig" -gravity South -splice 0x$spl "$filenew"

convert -background gold -fill black -gravity center -size ${width}x$spl \
caption:"$comment" \
"$filenew" +swap -gravity south -composite "$filenew"


Your suggestions would be greatly appreciated!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Improving my "caption:" code

Post by fmw42 »

You never defined width, but use it. Nevertheless, try this.

Code: Select all

declare `convert "$fileorig" -format "HH=%[fx:h/10]\nWW=%w\n" info:`
convert "$fileorig" \
-size ${WW}x${HH} -background white -fill black -undercolor gold -gravity center caption:"$comment" \
-append "$filenew"
Anton79
Posts: 2
Joined: 2019-09-20T22:44:27-07:00
Authentication code: 1152

Re: Improving my "caption:" code

Post by Anton79 »

Hi fmw42, Thanks very much for your help!
That took the elapsed run time in processing my test folder down from 45 seconds to 15 seconds.
A funny thing is happening though. All looks good in Nautilus in grid view. Gold box with black captions. But when you open the jpgs in Image Viewer or Shotwell Viewer only a white box displays and no caption. I look forward to your suggestions!
Post Reply