Two-tone 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
Masterjuggler
Posts: 2
Joined: 2020-01-27T15:32:50-07:00
Authentication code: 1152

Two-tone text

Post by Masterjuggler »

I'm making a set of game cards and I'd like to add some two-tone text onto each one, with the lower half silver and the upper half white. Here's an example of what I mean: Image

I wrote a bash script that's taking card stats off a csv file and using imagemagick to add them to the appropriate image in the correct location. As of right now, all I've seen are solid colors by name and picking rgb values. Maybe there's a simple way to do this, but I either didn't see it, or didn't recognize the answer in my searching. If anyone has any suggestions, I'd greatly appreciate it. Thanks!

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

Re: Two-tone text

Post by fmw42 »

I do not understand the question.

Do you need to know how to specify colors? See https://imagemagick.org/script/color.php

Or do you need to know how to put two colors onto the top and bottom of the image?

Post your original image. Also provide your IM version and platform (whenever asking questions, since syntax may vary).

Make an image that is white on the top half and light gray on the bottom half. Then do a -compose multiply -composite to combine it with your original.

User avatar
GeeMack
Posts: 753
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Two-tone text

Post by GeeMack »

There are several methods to get this result with ImageMagick. To get the best answers you need to provide your IM version and let us know which shell/OS you're using. Without more information, here are a couple simple ideas...

This first command creates two labels with the same text, one white on black and the other gray on black. Both labels are cropped horizontally into two equal parts. Then the bottom half of the white label and the top half of the gray one are deleted. Finally the remaining two parts are appended. The result is a transparent background with text that is white from the top down to half way, and gray from the half way line to the bottom.

Code: Select all

convert -pointsize 48 -background black -fill white label:"ABC 1 2 3" \
   -fill gray label:"ABC 1 2 3" -crop 1x2@ -delete 1,2 -append twotone.png
Keep in mind that command will cut the two images exactly in half, but the text will very likely not be exactly centered horizontally. If you want it centered better, use "-trim +repage" right before the crop, and add borders after the parts are appended to a single label.

The next command here creates a single label, white on transparent, then uses "-sparse-color" to fill it with white down to H*0.4, and gray from H*0.6 to the bottom. That makes a bit of gradient between H*0.4 and H*0.6 where the colors meet in the middle.

Code: Select all

convert -background none -pointsize 48 -fill white label:"ABC 1 2 3" -trim \
   -channel RGB -sparse-color barycentric "0,%[fx:h*0.4] white 0,%[fx:h*0.6] gray" twotone.png
That command uses "-trim" to get rid of excess bordering so the "-sparse-color" fills the text completely and aligns to the horizontal center, Add some border again after the "-sparse-color" operation if needed. Adjust the fractions in those FX expressions to change the location or distance of the gradient.

More information about your exact needs would help us give you better options.

Masterjuggler
Posts: 2
Joined: 2020-01-27T15:32:50-07:00
Authentication code: 1152

Re: Two-tone text

Post by Masterjuggler »

I'm running Imagemagick 6.9.7 on Ubuntu 18.04. Thanks for the suggestions, I ended up using -compose multiply -composite with a background image. I didn't see it in my initial search, and it definitely got me the end result I wanted. I appreciate the help!

Post Reply