Negated Text?

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
White

Negated Text?

Post by White »

Hello,

How to make negated label? I give you an example:
Image

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

Re: Negated Text?

Post by fmw42 »

No easy solution that I know about. Best I can think is to make the image twice, once with each text color. Then make a mask with the center horizontal band white and the rest black. Then use the mask to composite the two versions together so that the center uses the image with one text color and the rest of the image comes from the other text color.

see

http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/channels/#masks
White

Re: Negated Text?

Post by White »

Before posting I tried this:
With GIMP create mask.png file with transparent background.
After that:

Code: Select all

convert mask.png matte:- | convert - -negate mask2.png
convert mask2.png -fill white -pointsize 45 -draw "rotate -30 gravity Center fill white text 0,0 'Negated Text' " +matte mask3.png
composite -compose CopyOpacity mask3.png image.jpg stamp.png
convert stamp.png -negate negated_stamp.png
composite -gravity center image.jpg negated_stamp.png result.jpg
But result.jpg is just negated image.jpg.

fmw42 I'm not sure that I understand you correctly. Can you give example commands, please!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Negated Text?

Post by fmw42 »

fmw42 I'm not sure that I understand you correctly. Can you give example commands, please!
Here is an example, but it may not be the most efficient. But it works.

# create background
convert -size 500x100 xc:dodgerblue \
-gravity center -background gold -extent 500x300 text_bg.png
Image

# create mask from background
convert text_bg.png -channel blue -separate +channel -threshold 0 text_mask.png
http://www.fmwconcepts.com/misc_tests/t ... t_mask.png

# create text with first color on transparent background
convert -background none -font Candice -pointsize 60 -fill black \
label:'Test Contrast Text' \
-rotate 25 -gravity center -extent 500x300 text1.png
Image

# create text with second color on transparent background
convert -background none -font Candice -pointsize 60 -fill wheat \
label:'Test Contrast Text' \
-rotate 25 -gravity center -extent 500x300 text2.png
Image

# composite both text colors with mask
convert text1.png text2.png text_mask.png -compose over -composite text3.png
Image

# overlay composited text onto background
convert text_bg.png text3.png -compose over -composite text_final.png
Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Negated Text?

Post by anthony »

A -compose difference with a black and white mask will selectively negate the other image according to that mask. You can also try using the relatated compose method 'exclusive'.

See IM Examples, Compose, Difference
http://www.imagemagick.org/Usage/compose/#difference
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
White

Re: Negated Text?

Post by White »

I see where is my mistake. The last command from my previous post must be

Code: Select all

convert image.jpg negated_stamp.png -compose over -composite result.jpg
and it works. Thank you fmw42!

Code: Select all

composite mask3.png image.jpg -gravity center -compose difference result.jpg
works too and must be much more efficient.
Thank you anthony!
Post Reply