Page 1 of 1

Problems creating a png with text and transparent background

Posted: 2013-07-12T04:24:35-07:00
by jagku
Hello,

I have just started using imagemagick as I need to create very simple png's which contain text (certain font/size/colour - possibly bold/italic/underlined if the font supports it) on a transparent background.

I have tried doing this but when I lay out the PNG on to a coloured background, it just doesn't look very sharp due to the curves around the "e" and "o".

Code: Select all

convert  -density 90 -pointsize 72 -font Gill-Sans-MT -fill black -stroke black -transparent white -colorspace CMYK label:Hello test.png
(I have also tried adding +antialias before the "-font" - but the background becomes white (instead of remaining transparent).

Can anybody see where I am going wrong?

Thanks in advance!

Re: Problems creating a png with text and transparent backgr

Posted: 2013-07-12T05:54:32-07:00
by snibgo
"-transparent White" doesn't do what you probably think it does. (It's in the wrong position, and it turns only pixels that are entirely white to transparent. Pixels at the edge of the letters are various shades of gray.) Try "-background None" instead.

"-colorspace CMYK" does nothing here. (And it should be placed after "label:", not before.) If you want a CMYK file, save it as a tiff or jpg.

Re: Problems creating a png with text and transparent backgr

Posted: 2013-07-12T06:19:53-07:00
by jagku
Thanks alot - ah so the flags have to be in a certain order.
Problem solved!

Re: Problems creating a png with text and transparent backgr

Posted: 2013-07-12T06:36:32-07:00
by snibgo
It's always best to put them in logical order. The image isn't created until "label:", so anything that changes the images, such as "-transparent", should come after that. Anything that affects how the image is created, such as "-background", should come before "label:".

However, for reasons lost in the mists of time, putting "-transparent" before "label:" does actually work. But the curved letters have edges that blend with the background, so it doesn't do what you want.

Png files can't store CMYK. So your command tries to create an image, convert it to CMYK, then back to sRGB to store in the file.

Re: Problems creating a png with text and transparent backgr

Posted: 2013-07-12T06:43:14-07:00
by jagku
Thanks for the explanation.

Yes, PNG files certainly can't be saved as CMYK - I think I was running with my eyes shut!

Thanks once again!

Re: Problems creating a png with text and transparent backgr

Posted: 2013-07-28T18:15:41-07:00
by anthony
You may like to look at the examples on converting Postscript pages.
http://www.imagemagick.org/Usage/text/#postscript

Basically a good way of making white transparent, is you use the text image as a transparency mask, such that white is made fully transparent.

Code: Select all

convert text.png  -negate -background black -alpha shape  text_on_transparency.png