how can we stroke text 1px outside it

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
webad20
Posts: 3
Joined: 2011-02-03T06:45:47-07:00
Authentication code: 8675308

how can we stroke text 1px outside it

Post by webad20 »

In photoshop we can stroke text by choosing stroke position as outside. But I can not find the option in IM. It is usefull when we stroke small text like 12px. We can do the job by writing the text in four directions in stroke color and then write the text in fill color, but that's not nice. With +antialias it is impossible :(

Mean while +antialias make charecters ugly, especailly chinese charecters, even cannot be read. That is far diffrent from photoshop by setting antialias as none. Also, it is usefull dealing with small texts. Is there any way to handle these problems? We have to use small texts in our project, Athony's examples are all big texts :shock: .

The image below shows,
1st line, using label:text with +antialias
2nd line, annotating text
3rd line, write text in photoshop setting antialias=none
last line, stroke text outside in photoshop, I'd like IM to do the same thing.

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

Re: how can we stroke text 1px outside it

Post by fmw42 »

I don't think IM has that specific option. It stokes down the middle as far as I know. You would have to specify slightly different coordinates by half the strokewidth you want to get the effect you want.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: how can we stroke text 1px outside it

Post by anthony »

For a one pixel outside stroke you need to use a compount font.

draw/annotate/label the text with a 2 pixel stroke of the color desired.
Then repeat with the stroke color set to none, so as to remove the internal half of the stroke.
DO NOT adjust stroke width, or the second text draw may not line up with the first.

See... IM examples, Compound Fonts, Thick Stroke
http://www.imagemagick.org/Usage/fonts/#thick_stroke

I find this compound font very useful and use it extensively for other compound font variants on the same examples section.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
webad20
Posts: 3
Joined: 2011-02-03T06:45:47-07:00
Authentication code: 8675308

Re: how can we stroke text 1px outside it

Post by webad20 »

thanks to Anthony and others. unfortunately my fonts are not compound fonts. Again, today I tried under linux. -pointsize property does not work when used with label and my chinese fonts, each time they appear larger up to 20+ even I set pointsize to 6. I guess IM need more surpport to chinese fonts, while php gd2 works nice with my fonts.

I don't have time to read source code about fonts. I guess IM should be improved when convert vector fonts to bitmap show. Maybe using function 'floor' instead of 'round' is better when caculate a pixel should be filled or empty, pratically, adjusting the threshold is good. But that's not so simple, some more complecated codes are required to ensure the charecters are coutinuos.

Back to my project, I got a solution not so nice. First write text in php gd2, then add more effects like stroke in IM. It's suffering...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: how can we stroke text 1px outside it

Post by anthony »

Compound fonts is a 'drawing method' It is not specifically a type of font.

That is you draw fonts multiple times or with some sort of extra processing to generate interesting effects.

No special fonts are used.

In this case a 1px external stroke, is done by drawing the draw twice.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply