Putting serval pictures in a pipe and merge them with a background

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
outof
Posts: 2
Joined: 2017-09-06T10:04:23-07:00
Authentication code: 1151

Putting serval pictures in a pipe and merge them with a background

Post by outof » 2017-09-06T14:36:57-07:00

Dear ImageMagick community,
I started semi-automated command line editing for a small project a couple of weeks ago and got stuck during usage of pipes / virtual files.

The goal is to pick some jpg-Files from a directory, rotate and move them next to each other and merge them with the background. By using tmp png Files to enable transparency and sticking them together to a backgropund everything works fine:
Transform and rotate:

Code: Select all

convert 1.jpg -resize 50% -background none -rotate 1.png
Glue together:

Code: Select all

convert background.jpg -page +5+10 1.png -page +2100+10 2.png -background none -layers flatten output.jpg
For better IO-perfomance I want to skip the png part by using a pipe (and Miff-files):

Code: Select all

convert -page +5+10 -resize 40% -background none -rotate -4 1.jpg MIFF:-; \
-page +2150+10 -resize 40% -background none -rotate -4 2.jpg MIFF:- \
| convert background.jpg -background none MIFF:- -layers flatten +page +output.jpg
Unfortunately this only works for one input File 1.jpg. As soon as I add 2.jpg things stop to work as expected. After reading and trying a dozen examples including diffrent delimiters between the commands of 1.jpg and 2.jpg like ;| or using composite or montage to stick the pictures to the background I still have no solution. I even tried using brackets during conversion of the jpegs and diffrent alignments of the image manipulations.

Can you please help me to finish my performance optimization. Probably I'm not familiar with piping or using correct syntax for stdin and stdout but I couldn't find any working example.
Thank you

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Putting serval pictures in a pipe and merge them with a background

Post by fmw42 » 2017-09-06T14:54:57-07:00

Your syntax is not correct. You must read the input images before resizing and rotating. Also -page must come before reading the input. But it is easier to use -set page after processing the input images. Also MIFF will hold multiple layers, so you only need one MIFF:-. Use parenthesis processing to do each image (layer).

Try:

Code: Select all

convert \( 1.jpg -resize 40% -background none -rotate -4 -set page +5+10 \)  \
\( 2.jpg -resize 40% -background none -rotate -4 -set page +2150+10 \) MIFF:- \
| convert background.jpg -background none - -layers flatten output.jpg
In the future please always provide your IM version and platform, since syntax may differ.

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Putting serval pictures in a pipe and merge them with a background

Post by fmw42 » 2017-09-06T14:59:17-07:00

You can also do the same with -compose ... -composite using -geometry in pairs of images.

Code: Select all

convert background.jpg 
\( 1.jpg -resize 40% -background none -rotate -4 \) -geometry +5+10 -compose over -composite \
\( 2.jpg -resize 40% -background none -rotate -4 \) -geometry +2150+10 -compose over -composite \
output.jpg
see
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/basics/#parenthesis

outof
Posts: 2
Joined: 2017-09-06T10:04:23-07:00
Authentication code: 1151

Re: Putting serval pictures in a pipe and merge them with a background

Post by outof » 2017-09-18T11:38:24-07:00

Dear Fred,

thank you so much for your quick reply. It rather took me some time to test it and it works as expected :D
During my try n error runs using paraenthesis I missed the white spaces.
To complete my question, I'm using ImageMagick 6.8.9-9 on a Respian Jessie, so your syntax is correct.

Best regards

Post Reply