Page 1 of 1

Bug generating text on black frames

Posted: 2013-02-23T23:10:38-07:00
by salsaman
ImageMagick 6.7.5-6

The following commands generate text on green background, instead of the desired black background:

convert -quiet -colorspace RGB -type truecolor -alpha on -size 720!x480! xc:"#000000FF" temp.png
convert -quiet -colorspace RGB -type truecolor -alpha on temp.png -fill "#FFFFFFFF" -stroke "#FFFFFFFF" -pointsize 32 -draw "text 78 44 'Text'" 00000001.png

with just a slight adjustment it works almost as desired:

convert -quiet -colorspace RGB -type truecolor -alpha on -size 720!x480! xc:"#000001FF" temp.png
convert -quiet -colorspace RGB -type truecolor -alpha on temp.png -fill "#FFFFFFFF" -stroke "#FFFFFFFF" -pointsize 32 -draw "text 78 44 'Text'" 00000001.png

and:

convert -quiet -colorspace RGB -type truecolor -alpha on -size 720!x480! xc:"#000000FF" temp.jpg
convert -quiet -colorspace RGB -type truecolor -alpha on temp.jpg -fill "#FFFFFFFF" -stroke "#FFFFFFFF" -pointsize 32 -draw "text 78 44 'Text'" 00000001.png

also works OK.

Seems like in the first example a YUV colorspace is being used incorrectly.

Re: Bug generating text on black frames

Posted: 2013-02-24T00:49:18-07:00
by snibgo
Your version of IM is old, and at that time it was confused about RGB and sRGB. I suggest you upgrade, to at least 6.7.9.

The syntax for convert is:

Code: Select all

convert infile {options that change the image} outfile
Putting the options first might happen to work, but I suggest you don't.

JPG files can't store transparency. PNG files can.This shouldn't matter, as you are not using transparency.

The following seems to do what you want:

Code: Select all

convert -quiet -size 720x480 xc:"#000000FF" temp.png

convert -quiet temp.png -fill "#FFFFFFFF" -stroke "#FFFFFFFF" -pointsize 32 -draw "text 78 44 'Text'" 00000001.png
Or, perhaps a little clearer:

Code: Select all

convert -quiet -size 720x480 xc:Black temp.png

convert -quiet temp.png -fill White -stroke White -pointsize 32 -draw "text 78 44 'Text'" 00000001.png

Re: Bug generating text on black frames

Posted: 2013-02-24T05:50:57-07:00
by salsaman
Thanks for the prompt reply, and glad to learn it has been fixed.

I tested with fedora 17, so I will check for updates to the imagemagick package.

Regards.

Re: Bug generating text on black frames

Posted: 2013-02-24T06:14:12-07:00
by salsaman
BTW, the "convert -quiet -colorspace RGB -type truecolor [-alpha on]" is autogenerated by my code. I need a generic command which ensures (as much as possible) that the output image is in the RGB24 (for .jpg) or RGBA32 (for .png) colorspace. Due to current programatic limitations this has to come at the start of the command. I realise it is not really correct, but the reported bug is the only case I have come across where this fails. Certainly in the first command there is only an output image, so the options should be applied to it.

If you have a better suggestion which would not add complication to the code then I would be interested to know it.

Re: Bug generating text on black frames

Posted: 2013-02-24T07:13:58-07:00
by snibgo
We are told that IM V7 will not process commands given in the wrong order.

In current IM versions (since about 6.7.9), "-colorspace RGB" will change the pixel values from the current colourspace (presumed sRGB) to RGB. This will change the colours in your image, making them darker if the source is sRGB. It has no effect on the output file format (eg indexed, or number of channels).

As this image is almost entirely black and white, the conversion to RGB will have little effect. (It would be visible only in the anti-aliased edges of the text). A rule of thumb: don't change an image's colorspace unless you really want to.

"-alpha on" won't guarantee the output PNG contains an alpha channel. Prefixing the filename with "PNG32:" does.

Re: Bug generating text on black frames

Posted: 2013-02-24T12:12:27-07:00
by salsaman
Thanks for that tip !