Page 1 of 1

One line command to distort and compose image

Posted: 2017-09-08T07:13:37-07:00
by e-tip
Hi everyone i have an image ( it's a book cover ) that is composed by back, spine, and cover like in this image Image
Now with 3 convert commands i cut the blue part and distort it saving as cover.png, after that i crop the yellow part saving it as spine.png, and with a third command i compose those images obtaining this
Image
is there a way to do all this work in a single command?
I ask because the script that generates this image runs on aws lambda and saves the output to amazon s3 so less read/write i do better is..
thanks in advance

Re: One line command to distort and compose image

Posted: 2017-09-08T07:42:20-07:00
by snibgo
e-tip wrote:is there a way to do all this work in a single command?
Yes.

Re: One line command to distort and compose image

Posted: 2017-09-08T08:12:44-07:00
by e-tip
Good to know! thanks

Re: One line command to distort and compose image

Posted: 2017-09-08T08:20:58-07:00
by snibgo
If you show us the commands you currently use, we can show you how to combine them.

Re: One line command to distort and compose image

Posted: 2017-09-08T08:40:26-07:00
by e-tip
Here are the commands i use to generate my images and than compose
convert cover_design.png -crop 812x816+880+0 -resize 1060x1060! -matte -alpha set -virtual-pixel transparent -distort Perspective "0,0,277,653, 1060,0,629,549, 1060,1060,897,706, 0,1060,497,859" cover.png
convert cover_design.png -crop 67x816+814+0 -resize 1060x1060! -matte -virtual-pixel transparent -distort Perspective "0,0,277,670, 1060,0,277,653, 1060,1060,497,859, 0,1060,496,879" spine.png
convert -composite -geometry +0+0 cover.png spine.png composed_cover.png

thanks

Re: One line command to distort and compose image

Posted: 2017-09-08T09:12:05-07:00
by snibgo
Your final command should have "-geometry" after the inputs, and "-composite" after that, like this:

Code: Select all

convert cover.png spine.png  -geometry +0+0  -composite composed_cover.png
Your first two commands each take one input, and process it to make an output. So you can substitute the inputs and processing for the two files in the third command, putting them inside parentheses so the processing is restricted to the respective input.

Code: Select all

convert ( cover_design.png -crop 812x816+880+0 -resize 1060x1060! -matte -alpha set -virtual-pixel transparent -distort Perspective "0,0,277,653, 1060,0,629,549, 1060,1060,897,706, 0,1060,497,859"  ) ( cover_design.png -crop 67x816+814+0 -resize 1060x1060! -matte -virtual-pixel transparent -distort Perspective "0,0,277,670, 1060,0,277,653, 1060,1060,497,859, 0,1060,496,879" )  -geometry +0+0  -composite composed_cover.png
The parentheses need a space on both sides. If you use bash, you'll need to escape the parentheses: \( and \)

The command reads the file cover_design.png twice. We can save it in memory the first time, then read from memory the second time:

Code: Select all

convert ( cover_design.png +write mpr:COVERDES -crop 812x816+880+0 -resize 1060x1060! -matte -alpha set -virtual-pixel transparent -distort Perspective "0,0,277,653, 1060,0,629,549, 1060,1060,897,706, 0,1060,497,859"  ) ( mpr:COVERDES -crop 67x816+814+0 -resize 1060x1060! -matte -virtual-pixel transparent -distort Perspective "0,0,277,670, 1060,0,277,653, 1060,1060,497,859, 0,1060,496,879" )  -geometry +0+0  -composite composed_cover.png
I don't know what "-matte" does or used to do. I suggest you use only documented operations and settings.

Re: One line command to distort and compose image

Posted: 2017-09-08T09:53:43-07:00
by fmw42
snibgo wrote:I don't know what "-matte" does or used to do. I suggest you use only documented operations and settings.
It was the very old form of -alpha on/set. +matte was the old form of -alpha off.

So he has redundant commands of -matte -alpha set

Re: One line command to distort and compose image

Posted: 2017-09-11T00:10:07-07:00
by e-tip
Oh , thanks all. Especially for the comments about my wrong commands :)