Page 1 of 1

Building and compositing image in one step

Posted: 2018-09-04T15:32:45-07:00
by notkevinjohn
I have written code that works for a custom labeling application where labels are built and then printed on the fly. It all works properly, but execution speed is a problem. The code takes about ~3 second to run, and I need it to run much faster, maybe ~ < 1s. I am currently making the label overlays I need to place onto a template image as individual PNG files, and then compositing them together into the final file.

magick convert -background white \
-fill black -pointsize 70 -font Arial label:"$Week" \
-rotate "-90" \
time.png

magick convert -background white \
-fill black -pointsize 500 -font Free-3-of-9-Regular label:"$Barcode" \
-rotate "-90" \
barcode.png
magick convert barcode.png -resize 100x600\! barcode.png

magick convert -background white \
-fill black -pointsize 200 -font Arial-Bold label:"$Serial" \
serial.png

magick composite -geometry +320+950 serial.png template.png $output
magick composite -geometry +75+800 time.png $output $output
magick composite -geometry +75+150 barcode.png $output $output

can someone point me in the right direction on taking these steps where files are written to the drive (slowly) and compiling all this together into a single convert command such that the entire operation is done in memory?

Re: Building and compositing image in one step

Posted: 2018-09-04T16:21:06-07:00
by snibgo
I suggest you first change all the commands so every one is "magick". Not "magick convert" or "magick composite", but just "magick" by itself.

This will give you a series of commands. Some of them can be easily combined, eg one command creates barcode.png, and the next command reads that file, resizes it and writes it. Instead, you can do the resize as the last operation of the first command.

When combining all the "magick" commands into one, you will need either to use parentheses, or to write to "mpr:" and read from it.

But first, re-write to just use "magick".