Page 1 of 1
Text fill bleeds around stroke
Posted: 2015-11-29T17:59:53-07:00
by arrenlex
I get pretty strange output trying to generate outlined text with imagemagick, even for very simple commands:
Code: Select all
convert -size 320x100 xc:black -gravity center -stroke black -fill white -strokewidth 1 -font Arial-Bold -pointsize 40 -annotate +0+0 "This is a bridge" output.png
Here it is zoomed in to the g in bridge:
Does anyone know what causes this kind of bleed-through?
Code: Select all
$ convert -version
Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
Thanks!
Re: Text fill bleeds around stroke
Posted: 2015-11-29T20:05:12-07:00
by fmw42
First your IM version 6.7.7.10 is ancient (about 150 versions old). You might get better results if you can upgrade.
The issue you see is from antialiasing, especially with a stroke added and one that is not the same as the fill color.
You will get a better result if you leave off the -stroke and -strokewidth
Code: Select all
convert -size 320x100 xc:black -gravity center -fill white -font Arial-Bold -pointsize 40 -annotate +0+0 "This is a bridge" output.png
or use a stroke color the same as the fill color
Code: Select all
convert -size 320x100 xc:black -gravity center -stroke white -fill white -strokewidth 1 -font Arial-Bold -pointsize 40 -annotate +0+0 "This is a bridge" output.png
or add +antialias to the command without the stroke and strokewidth
Code: Select all
convert -size 320x100 xc:black -gravity center -fill white -font Arial-Bold -pointsize 40 +antialias -annotate +0+0 "This is a bridge" output.png
Re: Text fill bleeds around stroke
Posted: 2015-11-29T20:11:28-07:00
by arrenlex
Hi, fmw42;
This imagemagick version is whatever comes on the latest ubuntu LTS; that's what our servers are running. It would be difficult to upgrade our servers to a nonstandard version, but it's something I can look into if it fixes the issue. (can you reproduce it on the latest version?)
I'm not sure I understand your advice to leave off the stroke. In my actual program, this text will be rendered overtop of an arbitrary photograph instead of a black background, so I want to have an outline around the text to prevent it from blending into whatever features might be in that area of the photograph.
Thanks for the help!
Re: Text fill bleeds around stroke
Posted: 2015-11-29T22:15:24-07:00
by fmw42
I get the same results as you on IM 6.9.2.7 Q16. It is an anti-aliasing issue.
It is working correct at normal viewing size as far as I can see. Why do you need to enlarge the text to the point that the antialiasing is visible?
Add +antialias to remove the antialiasing gray. Here I put it on a transparent background. But it will look more blocky.
Code: Select all
convert -size 320x100 xc:none -gravity center -stroke black -fill white -strokewidth 1 -font Arial-Bold -pointsize 40 +antialias -annotate +0+0 "This is a bridge" output.png
Re: Text fill bleeds around stroke
Posted: 2015-11-29T22:21:25-07:00
by arrenlex
The issue is very visible at normal size. I notice that some png rendering engines expose it to a lesser or greater extent. Firefox's seems to be pretty good; imagemagick's seems to be particularly bad.
Here I've opened the image with the 'display' command and took a screenshot of the results. The result seems pretty noticeable to me. Do you see it here?
Re: Text fill bleeds around stroke
Posted: 2015-11-29T23:12:08-07:00
by fmw42
No not really. I only see the smooth edges from the antialiasing. see
https://en.wikipedia.org/wiki/Aliasing
You can inquire further from the developers on the Developer's forum.