Page 1 of 1

Best way to write alpha channel multi-line text over image

Posted: 2013-03-09T13:38:17-07:00
by dfavor
Goals... In the case where 1000s of these pipelines run simultaneously...

1) Single command, no intermediate files

2) Must handle multi-line images, hence label rather than draw

3) Text image must have alpha channel, so background image shows through

4) Least load on CPU + intermediate memory

5) Final image must be a .jpg

I'd rather use draw, except draw fails to convert "\n". If there's a way to have draw correctly render "\n", let me know.

Seems like there'd be less memory used if the size didn't have to be specified in the first convert and this was the only way I could get this working.

Here's one version of this pipeline that works... and it's a bit slow...

convert -size 1563x2500 -transparent white -font URW-Palladio-L-Bold-Italic -pointsize 100 -gravity center -fill purple 'label:this is a test' png:- |\
composite -size 1563x2500 -compose dstover -gravity center -geometry +0+0 back.png - png:- |\
convert - output.jpg

Gurus, any suggestions as to how I might refine this pipeline?

Thanks.

Re: Best way to write alpha channel multi-line text over ima

Posted: 2013-03-09T14:30:54-07:00
by snibgo
The requirement might be clearer if you provided a sample.

1. Why write to a PNG, then convert that to a JPG? If you also need a PNG, you could write it in the middle of a "convert" command.

2. Why use "composite"? You can probably do the same job in a "convert".

3. Then combine the three converts into a single command, with no intermediate files or pipes.

Re: Best way to write alpha channel multi-line text over ima

Posted: 2013-03-10T06:25:02-07:00
by dfavor
The application consuming the final image only consumes .jpg files, hence the final convert.

Initial operations occur with png files to support transparency (alpha channel), so any random
image may be used as a background, then written on.

I just used the form I did to illustrate my pipeline, as it's easier to hack in scripts with no \( ... \) syntax.

One the optimal pipeline is determined, I'll switch to the convert syntax using \( ... \) syntax.

The primary question right now is...

1) Let me know if there's a way to use draw to render multi-line text, so draw effects can be used.

Thanks.

Re: Best way to write alpha channel multi-line text over ima

Posted: 2013-03-10T06:28:11-07:00
by dfavor
Just found my answer. Using annotate is required (as in label) as draw is unable to render newlines.