Moving a caption

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
vik
Posts: 4
Joined: 2012-03-12T13:22:24-07:00
Authentication code: 8675308

Moving a caption

Post by vik »

I'm trying to use ImageMagick to add an auto-sizing caption to an image. However the text is too close to the bottom edge of the image. I want to move it up. I tried adding a +0+15 to the gravity option but it didn't work. Here's the command I'm using:

convert -resize -500x <src file name> -size 470x60 -gravity south -background #0000 -font Impact -stroke #000C -strokewidth 6 caption:"Test" -composite -size 470x60 -gravity south -background #0000 -font Impact -stroke none -fill #fff caption:"Test" -composite <dst file name>

I'm running the latest version and plan to use this command in a php script.

Please help. Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Moving a caption

Post by fmw42 »

try

convert \( <src file name> -resize -500x \) \
\( -size 470x60 -background #0000 -font Impact -stroke "#000C" -strokewidth 6 caption:"Test" \) \
-gravity south -geometry +0+15 -composite \
\( -size 470x60 -background #0000 -font Impact -stroke none -fill "#fff" caption:"Test" \) \
-gravity south -geometry +0+15 -composite <dst file name>

On windows, change \( ... \) to ( ... ) and the end of line \ change to ^

Also you need to quote your hex (and any rgb) color values. Also your syntax is not current IM 6. You need to read your input image before the resize, though it should not matter.

see
http://www.imagemagick.org/Usage/basics/#cmdline
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/script/color.php
http://www.imagemagick.org/Usage/windows/
vik
Posts: 4
Joined: 2012-03-12T13:22:24-07:00
Authentication code: 8675308

Re: Moving a caption

Post by vik »

It didn't work. I am using the following command now:

/usr/local/bin/convert \("<src file name>" -resize 500x\)' \( -size '470x60' -background '#0000' -font Impact -stroke '#000C' -strokewidth 6 caption:"<caption here>" \)\ -gravity north -geometry +0-15 -composite \( -size '470x60' -background '#0000' -font Impact -stroke none -fill '#fff' caption:"<caption here>" \)\ -gravity north -geometry +0-15 -composite \( -size '470x60' -background '#0000' -font Impact -stroke '#000C' -strokewidth 6 caption:"<caption here>" \)\ -gravity south -geometry +0+15 -composite \( -size '470x60' -background '#0000' -font Impact -stroke none -fill '#fff' caption:"<caption here>" \)\ -gravity south -geometry +0+15 -composite "<dst file name>"

I think the only think missing is line endings.

EDIT: Noticed some syntax issues but it still didn't work. New command:
/usr/local/bin/convert \("<src file name>" -resize 500x\) \ \( -size '470x60' -background '#0000' -font Impact -stroke '#000C' -strokewidth 6 caption:"<caption here>" \) \ -gravity north -geometry +0-15 -composite \( -size '470x60' -background '#0000' -font Impact -stroke none -fill '#fff' caption:"<caption here>" \) \ -gravity north -geometry +0-15 -composite \( -size '470x60' -background '#0000' -font Impact -stroke '#000C' -strokewidth 6 caption:"<caption here>" \) \ -gravity south -geometry +0+15 -composite \( -size '470x60' -background '#0000' -font Impact -stroke none -fill '#fff' caption:"<caption here>" \) \ -gravity south -geometry +0+15 -composite "<dst file name>"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Moving a caption

Post by fmw42 »

If it is still not working, post a link to an example image with the corresponding command line using the number for sizes that correspond to the image.

What version of IM and platform are you running.
vik
Posts: 4
Joined: 2012-03-12T13:22:24-07:00
Authentication code: 8675308

Re: Moving a caption

Post by vik »

The new syntax fails to generate an image at all. Here is the url but I've set it to simply output the command for now.

http://kaptionking.com/media/gm/mid/49/kid/210

This is the page on the site. I want to be able to generate an image for any caption on demand.
http://kaptionking.com/media/p/id/49

I'm running a CentOS box.

Version: ImageMagick 6.7.5-10 2012-03-08 Q16 http://www.imagemagick.org.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Moving a caption

Post by fmw42 »

You need to tell caption either a width and height or a width and pointsize. Try this


convert logo: \( -size 100x -background none -fill red -font Arial -pointsize 40 -gravity center caption:"this is some text" \) \
-gravity south -geometry +0+15 -compose over -composite logo_caption1.png

or


convert logo: \( -size 100x100 -background none -fill red -font Arial -gravity center caption:"this is some text" \) \
-gravity south -geometry +0+15 -compose over -composite logo_caption2.png


However, on my system with PANGO enabled, caption is not honoring the centering. I will report as a bug.
vik
Posts: 4
Joined: 2012-03-12T13:22:24-07:00
Authentication code: 8675308

Re: Moving a caption

Post by vik »

The full command:
/usr/local/bin/convert \("<src file name>" -resize 500x\) \ \( -size '470x60' -background '#0000' -font Impact -stroke '#000C' -strokewidth 6 caption:"<caption here>" \) \ -gravity north -geometry +0-15 -composite \( -size '470x60' -background '#0000' -font Impact -stroke none -fill '#fff' caption:"<caption here>" \) \ -gravity north -geometry +0-15 -composite \( -size '470x60' -background '#0000' -font Impact -stroke '#000C' -strokewidth 6 caption:"<caption here>" \) \ -gravity south -geometry +0+15 -composite \( -size '470x60' -background '#0000' -font Impact -stroke none -fill '#fff' caption:"<caption here>" \) \ -gravity south -geometry +0+15 -composite "<dst file name>"

Simplified:
convert \("<src file name>" -resize 500x\) \
\( -size '470x60' -background '#0000' -font Impact -stroke '#000C' -strokewidth 6 caption:"<caption here>" \) \ -gravity south -geometry +0+15 -composite
\( -size '470x60' -background '#0000' -font Impact -stroke none -fill '#fff' caption:"<caption here>" \) \ -gravity south -geometry +0+15 -composite
"<dst file name>"

I bolded the part where I specify a width and a height.

I need it to be centered so using PANGO and logo won't work right?

Perhaps I can tackle this from another angle? If I create an image that's 30x30 smaller and only has the captions then composite it with the original and center gravity it, will that work? If so, how would I go about doing it that way?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Moving a caption

Post by fmw42 »

try this, does it work, if so, then do the same with your image.

convert logo: \( -size 100x100 -background none -fill red -font Arial -gravity center caption:"this is some text" \) \
-gravity south -geometry +0+15 -compose over -composite logo_caption2.png
Post Reply