Question about 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
Don
Posts: 47
Joined: 2013-05-09T14:10:43-07:00
Authentication code: 6789

Question about caption:

Post by Don »

Hello there,

I was searching around and it seems that gradient fill only works for -annotate and not for caption:?

I was wondering if it's possible to apply a gradient fill to text created with caption:

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

Re: Question about caption:

Post by fmw42 »

Gradient fill is not a direct option for caption:. But you can do it with more in the command line by creating a gradient after the fact and then composing the text over the gradient. Try (unix syntax)

Code: Select all

convert -size 256x -pointsize 64 -background none \
-fill red -font Arial -gravity center caption:"Testing" \
\( -clone 0 -alpha opaque -sparse-color Barycentric '0,0 black  %[fx:w-1],0 white' \) \
+swap -compose over -composite caption_gradient_background.png
Image

or

Code: Select all

convert -size 256x -pointsize 64 -background none -fill red -font Arial -gravity center caption:"Testing" \
\( -clone 0 -alpha opaque -sparse-color Barycentric '0,0 black  %[fx:w-1],0 white' \) \
-compose dstover -composite caption_gradient_background.png
See http://www.imagemagick.org/Usage/canvas ... _gradients

Please always provide your IM version and platform, since syntax may differ
Don
Posts: 47
Joined: 2013-05-09T14:10:43-07:00
Authentication code: 6789

Re: Question about caption:

Post by Don »

Hello, thanks for response.

I apologize for not being more precise, I meant is it possible to apply a gradient to text using caption?

For example, the word testing to go from black to white like how it is in the second example in the following link: http://www.imagemagick.org/Usage/fonts/

From what I gathered, it seems to only work with annotate.

Thanks again.

P.S. IM version: ImageMagick 6.9.1-0 Platform: Linux
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Question about caption:

Post by fmw42 »

Not directly. But this works for me (by creating a mask of the text and compositing it to control the mix of the gradient and the background)

Code: Select all

convert -size 256x -pointsize 64 -background black \
-fill white -font Arial -gravity center caption:"Testing" \
\( -clone 0 -alpha opaque -sparse-color Barycentric '0,0 black  %[fx:w-1],0 white' \) \
\( -clone 0 -alpha opaque -fill red -colorize 100 \) \
-reverse -compose over -composite caption_gradient.png
Image
Don
Posts: 47
Joined: 2013-05-09T14:10:43-07:00
Authentication code: 6789

Re: Question about caption:

Post by Don »

Hmm that looks about right... would it be possible though to have the gradient go vertically and if the background can be transparent?

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

Re: Question about caption:

Post by fmw42 »

Code: Select all

convert -size 256x -pointsize 64 -background black \
-fill white -font Arial -gravity center caption:"Testing" \
\( -clone 0 -alpha opaque -sparse-color Barycentric '0,0 black  0,%[fx:h-1], white' \) \
\( -clone 0 -alpha transparent \) \
-reverse -compose over -composite caption_gradient2.png
Image
Don
Posts: 47
Joined: 2013-05-09T14:10:43-07:00
Authentication code: 6789

Re: Question about caption:

Post by Don »

Hello, that is great! Thanks!

I tried to add a stroke to it but doing the following but no results.. is it possible to add stroke?

Code: Select all

convert -size 256x -pointsize 64 -background black -fill white -font Arial -stroke yellow -strokewidth 2 -gravity center caption:"Testing" \( -clone 0 -alpha opaque -sparse-color Barycentric '0,0 black  0,%[fx:h-1], white' \) \( -clone 0 -alpha transparent \) -reverse -compose over -composite caption_gradient2.png
As always, thank you again!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Question about caption:

Post by fmw42 »

It is possible, but not directly. It gets even more complicated. But you might take a look at my texteffect script at the link below. For example:

Code: Select all

texteffect -t "SOME GRADIENT TEXT" -s outline -e normal -f Arial -p 48 \
-c red-blue -b none -o yellow -l 3 -u none -A 0 gradient_outline_text.png
Image

The script does not wrap text however. So it is more like label: than caption:
Post Reply