Page 1 of 1
text on transparent background problem
Posted: 2010-03-26T06:23:47-07:00
by danielHeen
Hey Y'all!
I'm trying to add text to a transparent image, but without nice results. The weird thing is that this works on versions 6.2.1 and 6.5.1, but not 6.6.0-8 I'm currently using.
It seems that the antialiasing get's "eaten" up in the process and the letters look "crumbly".
Tried this command:
Code: Select all
convert -size 500x250 xc:transparent -pointsize 29 -draw "fill white gravity center text 0,0 'testing'" text.tif
Also tried xc:none with same result, but if i set xc:black it looks great!?
Could there be any compile flags I've missed?
All help is good help
,
-Daniel
Re: text on transparent background problem
Posted: 2010-03-26T09:40:57-07:00
by fmw42
this looks fine to me (pull the -fill and -gravity out of the -draw)
convert -size 500x250 xc:none -pointsize 29 -fill white -gravity center -draw "text 0,0 'testing'" tmp.png
IM 6.6.0-9 Q16 Mac OSX Tiger
Re: text on transparent background problem
Posted: 2010-03-26T12:22:38-07:00
by danielHeen
Hey!
I also get a good result using png, but when I create a tif it looks crumbled.
What I'm doiing is using this as a part of a slate system and compose the tif over the images that need slating. When I use the png the result isn't as nice as with the tif. (On another version then 6.6.0-8, that is.)
I read somewhere that the same problem could appear on Gif's. Any knowledge on that? or if it's the same thing?
-Daniel
Re: text on transparent background problem
Posted: 2010-03-26T14:14:07-07:00
by fmw42
PNG and TIFF support 24 or 32-bit images, but GIF only supports 8-bits. Also gif transparency is binary, but PNG is 8-bit.
Re: text on transparent background problem
Posted: 2010-03-26T14:25:17-07:00
by fmw42
when I do
convert -size 500x250 xc:none -pointsize 29 -fill white -gravity center -draw "text 0,0 'testing'" tmp.tif
I get black letters that are not so good.
Looking at the verbose info:
PNG: (you get 8-bit grayscale and alpha)
identify -verbose tmp.png
Image: tmp.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 500x250+0+0
Resolution: 72x72
Print size: 6.94444x3.47222
Units: Undefined
Type: GrayscaleMatte
Base type: GrayscaleMatte
Endianess: Undefined
Colorspace: RGB
Depth: 16/8-bit
Channel depth:
gray: 1-bit
alpha: 8-bit
Channel statistics:
Gray:
min: 0 (0)
max: 65535 (1)
mean: 437.25 (0.006672)
standard deviation: 5335.16 (0.0814094)
kurtosis: 144.887
skewness: 12.1197
Alpha:
min: 0 (0)
max: 65535 (1)
mean: 65203.1 (0.994936)
standard deviation: 4391.97 (0.0670172)
kurtosis: 192.697
skewness: -13.7951
But with TIF: (you get bilevel 1-bit b/w and 1-bit alpha)
identify -verbose tmp.tif
Image: tmp.tif
Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 500x250+0+0
Resolution: 72x72
Print size: 6.94444x3.47222
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: MSB
Colorspace: RGB
Depth: 1-bit
Channel depth:
gray: 1-bit
alpha: 1-bit
Channel statistics:
Gray:
min: 0 (0)
max: 1 (1)
mean: 0.006672 (0.006672)
standard deviation: 0.0814094 (0.0814094)
kurtosis: 144.887
skewness: 12.1197
Alpha:
min: 0 (0)
max: 1 (1)
mean: 0.996928 (0.996928)
standard deviation: 0.0553404 (0.0553404)
kurtosis: 320.524
skewness: -17.959
So trying
convert -size 500x250 xc:none -pointsize 29 -fill white -gravity center -draw "text 0,0 'testing'" -depth 8 -type grayscalematte tmp2.tif
Now looks like png.
identify -verbose tmp2.tif
Image: tmp2.tif
Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 500x250+0+0
Resolution: 72x72
Print size: 6.94444x3.47222
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: MSB
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 1-bit
alpha: 8-bit
Channel statistics:
Gray:
min: 0 (0)
max: 255 (1)
mean: 1.70136 (0.006672)
standard deviation: 20.7594 (0.0814094)
kurtosis: 144.887
skewness: 12.1197
Alpha:
min: 0 (0)
max: 255 (1)
mean: 253.709 (0.994936)
standard deviation: 17.0894 (0.0670172)
kurtosis: 192.697
skewness: -13.7951
Re: text on transparent background problem
Posted: 2010-03-27T00:17:38-07:00
by danielHeen
That did the trick!! Thank you so much!
I suspect there is something fishy with the tiff module in IM. We're also having trouble with speed using tif's on nfs mounts. Found out that we had to use the following code to match the speed working on a local file system
Code: Select all
-define tiff:rows-per-strip=8 (or more)
Thanks again!
-Daniel
Re: text on transparent background problem
Posted: 2010-03-28T08:42:49-07:00
by danielHeen
Hey!
I found out that if I used rgba(100%,100%,100%,75%) format it didn't work again. I had to use a float number for the alpha to get the proper alpha mask.
in other words, this works:
Code: Select all
convert -size 1920x1080 xc:none -pointsize 29 -draw "fill 'rgba(100%,100%,100%,0.75)' gravity northWest text 20,20 'Shot:' " -compress lzw -depth 8 -type grayscalematte output.tif
this doesn't:
Code: Select all
convert -size 1920x1080 xc:none -pointsize 29 -draw "fill 'rgba(100%,100%,100%,75%)' gravity northWest text 20,20 'Shot:' " -compress lzw -depth 8 -type grayscalematte output.tif
Just wanted to let everyone know in case they run into the same problem.
Thanks again fmw42!
-Daniel
Re: text on transparent background problem
Posted: 2010-03-28T11:52:18-07:00
by fmw42
that is true, alpha values are specified in range 0-1, but the rest can be raw values 0-255 or percent values. That is just the way it is defined in IM
see
http://www.imagemagick.org/script/color.php
edit you can play around with colors with the color converter link/app near the top of the page
Re: text on transparent background problem
Posted: 2010-03-28T11:57:31-07:00
by magick
We try to follow standards whenever possible, see
http://www.w3.org/TR/css3-color/#rgba-color:
- 4.2.2 RGBA color values
[The RGB color model is extended in this specification to include ‘alpha’ to allow specification of the opacity of a color. See simple alpha compositing for details. These examples all specify the same color:
Example(s):
em { color: rgb(255,0,0) } /* integer range 0 - 255 */
em { color: rgba(255,0,0,1) /* the same, with explicit opacity of 1 */
em { color: rgb(100%,0%,0%) } /* float range 0.0% - 100.0% */
em { color: rgba(100%,0%,0%,1) } /* the same, with explicit opacity of 1 */
The format of an RGBA value in the functional notation is ‘rgba(’ followed by a comma-separated list of three numerical values (either three integer values or three percentage values), followed by an <alphavalue>, followed by ‘)’. The integer value 255 corresponds to 100%, rgba(255,255,255,0.8) = rgba(100%,100%,100%,0.8). White space characters are allowed around the numerical values.
Implementations must clip the red, green, and blue components of RGBA color values to the device gamut according to the rules for the RGB color value composed of those components.
These examples specify new effects that are now possible with the new rgba() notation:
Example(s):
p { color: rgba(0,0,255,0.5) } /* semi-transparent solid blue */
p { color: rgba(100%, 50%, 0%, 0.1) } /* very transparent solid orange */
[/list]