Page 1 of 1

How to draw text antialiased on alpha channel only

Posted: 2015-07-21T06:16:56-07:00
by ramaglabs
We are upgrading from an old version of ImageMagick and finding that a command we have previously used now produces different results.

In ImageMagick 6.7.3-9 the following produces greyscale text on a transparent background, where the text is a solid colour (#AAAAAA) and is antialiased against the transparent background on the alpha channel only:

Code: Select all

convert -background transparent -resize 1024x768 -fill '#AAAAAAB8' -font Arial -pointsize 50 label:'Test Stamp' test.png
In ImageMagick 6.9.1-2 the same command produces greyscale text on a transparent background where the text is antialiased on the RGB channels (i.e. pixels are shades of grey). It appears that the pixel colour '#AAAAAA' gets scaled by the alpha value '#B8', so that the brightest pixel becomes '7A'.

ImageMagick 6.7.3-9:
Image

ImageMagick 6.9.1-2:
Image

How do we get ImageMagick 6.9.1-2 to produce the same results as the older version?

Re: How to draw text antialiased on alpha channel only

Posted: 2015-07-21T06:54:45-07:00
by 246246
ramaglabs wrote: How do we get ImageMagick 6.9.1-2 to produce the same results as the older version?
I am not sure but is it what you want?

Code: Select all

convert -background transparent -resize 1024x768 -fill '#AAAAAAB8' -font Arial -pointsize 50 label:'Test Stamp' PNG8:test.png
identify -verbose test.png
...
Alpha: graya(0,0) #00000000
Colors: 2
Histogram:
197335: ( 0, 0, 0, 0) #00000000 graya(0,0)
40233: (170,170,170,255) #AAAAAAFF graya(170,1)
...

Re: How to draw text antialiased on alpha channel only

Posted: 2015-07-21T08:02:12-07:00
by ramaglabs
Thanks, but not quite. That produces text that's the correct colour (#AAAAAA) but has a hard outline and is not semi transparent. What I am looking for is the pixels to be '#AAAAAAB8' except around the glyph edges where they should blend with the transparent background, so have varying alpha values, e.g. for the old ImageMagick we get:

Code: Select all

$ identify -verbose test.png
  Alpha: graya(0,0,0,0)   #00000000
  Colors: 200
  Histogram:
    158362: (  0,  0,  0,  0) #00000000 graya(0,0,0,0)
     13398: (170,170,170,  0) #AAAAAA00 graya(170,170,170,0)
     12851: (170,170,170,184) #AAAAAAB8 graya(170,170,170,0.721569)
      3891: (170,170,170,185) #AAAAAAB9 graya(170,170,170,0.72549)
      2297: (170,170,170,186) #AAAAAABA graya(170,170,170,0.729412)
      1693: (170,170,170,187) #AAAAAABB graya(170,170,170,0.733333)
      1484: (170,170,170,  1) #AAAAAA01 graya(170,170,170,0.00392157)
      1370: (170,170,170,188) #AAAAAABC graya(170,170,170,0.737255)
      1310: (170,170,170,190) #AAAAAABE graya(170,170,170,0.745098)
...

Re: How to draw text antialiased on alpha channel only

Posted: 2015-07-21T08:53:21-07:00
by glennrp
Looks like the old sRGB versus linear problem is contributing to this.

Re: How to draw text antialiased on alpha channel only

Posted: 2015-07-21T10:23:49-07:00
by fmw42
It is a bug in IM 6.9.1.5 onward. See viewtopic.php?f=3&t=28081. Similarly, it is a bug in 6.9.1.2 and 6.9.1.3 versions. It seems to be fine before 6.9.1.2 and in 6.9.1.4.

Re: How to draw text antialiased on alpha channel only

Posted: 2015-07-21T20:25:25-07:00
by 246246
glennrp wrote:Looks like the old sRGB versus linear problem is contributing to this.
Ah, so if the text is black the problem doesn't occur (checked with 6.9.1-3 on Cygwin).

So workaround may be:

Code: Select all

convert -background transparent  -resize 1024x768 -fill '#000000B8' -font Arial -pointsize 50 label:'Test Stamp' -alpha off -fill '#AAAAAA' -opaque black -alpha on test.png
It looks similar result is generated but I don't know how antialias exactly works.
(On Cygwin, Arial not found, so I omit -font for this test. Also I'm not sure if this works on 6.9.1-2.)

Alpha: graya(170,0) #AAAAAA00
Colors: 196
Histogram:
133270: (170,170,170, 0) #AAAAAA00 graya(170,0)
10808: (170,170,170,184) #AAAAAAB8 graya(170,0.721569)
4141: (170,170,170,185) #AAAAAAB9 graya(170,0.72549)
2974: (170,170,170,186) #AAAAAABA graya(170,0.729412)
1965: (170,170,170,187) #AAAAAABB graya(170,0.733333)
1565: (170,170,170,183) #AAAAAAB7 graya(170,0.717647)
1537: (170,170,170, 1) #AAAAAA01 graya(170,0.00392157)

But the current 6.9.1-9 release on Windows, it does not work. As Fred said, it seems there stays another problem.

[EDIT]
With 6.9.1-9 on Windows

Code: Select all

convert -background transparent  -resize 1024x768 -fill '#000000B8' -font Arial -pointsize 50 label:'Test Stamp' -type 'TrueColorAlpha' -alpha off -fill '#AAAAAA' -opaque black -alpha on test.png
seems to work as well.

Alpha: graya(170,0) #AAAAAA00
Colors: 198
Histogram:
168052: (170,170,170, 0) #AAAAAA00 graya(170,0)
10458: (170,170,170,184) #AAAAAAB8 graya(170,0.721569)
4593: (170,170,170,185) #AAAAAAB9 graya(170,0.72549)
2812: (170,170,170,186) #AAAAAABA graya(170,0.729412)
1752: (170,170,170,187) #AAAAAABB graya(170,0.733333)
1532: (170,170,170,188) #AAAAAABC graya(170,0.737255)
1288: (170,170,170,183) #AAAAAAB7 graya(170,0.717647)

Re: How to draw text antialiased on alpha channel only

Posted: 2015-07-27T07:47:37-07:00
by ramaglabs
246246 wrote:
glennrp wrote:Looks like the old sRGB versus linear problem is contributing to this.
With 6.9.1-9 on Windows

Code: Select all

convert -background transparent  -resize 1024x768 -fill '#000000B8' -font Arial -pointsize 50 label:'Test Stamp' -type 'TrueColorAlpha' -alpha off -fill '#AAAAAA' -opaque black -alpha on test.png
seems to work as well.

Alpha: graya(170,0) #AAAAAA00
Colors: 198
Histogram:
168052: (170,170,170, 0) #AAAAAA00 graya(170,0)
10458: (170,170,170,184) #AAAAAAB8 graya(170,0.721569)
4593: (170,170,170,185) #AAAAAAB9 graya(170,0.72549)
2812: (170,170,170,186) #AAAAAABA graya(170,0.729412)
1752: (170,170,170,187) #AAAAAABB graya(170,0.733333)
1532: (170,170,170,188) #AAAAAABC graya(170,0.737255)
1288: (170,170,170,183) #AAAAAAB7 graya(170,0.717647)
Thanks - I can confirm the above does work when tested in ImageMagick 6.9.1-2. We found a few other places in our app where we generate text via IM that also has similar problems, so rather than change them all to use this work around, we switched to using ImageMagick 6.9.1-4. As fmw42 points out that version doesn't have this bug. This works for us for now, and hopefully when we next update IM that bug will be resolved.

Re: How to draw text antialiased on alpha channel only

Posted: 2015-07-27T08:25:50-07:00
by dlemstra
ImageMagick 6.9.1-10 has been released this weekend.