问题
for a little photo booth application have this problem:
I have 4 pictures, which i would like to tile together, using montage. The result get a 150px border using a transparent PNG and composite. But because the "frame" is larger than the base image, I have to add an additional convert to add artificial 150px border around the tiled image.
This is functional but very slow and seems not very elegant:
gm montage -geometry +20+20 -tile 2x2 /home/pi/dev/*.jpg miff:- | gm convert -border 150x150 miff:- miff:- | gm composite /home/pi/dev/rahmen.png miff:- /home/pi/dev/partyknipse.JPG
Is there any way I could optimize this and speed up the process? Get rid of the convert?
I guess the -geometry parameter of the composite could be useful, but didn't fully understand it so far.
This is roughly what it should look like in the end: red border is a png, the four grey boxes are the tiled image
回答1:
Not sure how long your operations take, or what you expect, but here are a couple of ideas...
Assume I have im1.jpg
through m4.jpg
which are the 4 small images and a larger red frame that is a "hollow" PNG with a transparent hole in the middle.
Firstly, if you were to switch to ImageMagick (rather than GraphicsMagick) you could do it all in one go with:
convert frame.png -background white -flatten \
im1.jpg -geometry +80+80 -composite \
im2.jpg -geometry +260+80 -composite \
im3.jpg -geometry +80+200 -composite \
im4.jpg -geometry +260+200 -composite result.png
Second, you could try something like this batching GraphicsMagick and storing intermediate steps in memory (MPR = Magick Program Register) which is effectively a named lump of RAM:
{ echo convert frame.png -background white -flatten mpr:frame;
echo montage -geometry +20+20 -tile 2x2 im*.jpg mpr:images;
echo composite mpr:images -geometry +100+40 mpr:frame result.png; } | gm batch -prompt off
来源:https://stackoverflow.com/questions/34118736/graphicsmagick-tips-for-optimizing-montage-and-composite