Building and compositing image in one step

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
notkevinjohn
Posts: 4
Joined: 2018-09-04T15:25:08-07:00
Authentication code: 1152

Building and compositing image in one step

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Building and compositing image in one step

Post 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".
snibgo's IM pages: im.snibgo.com
Post Reply