One line command to distort and compose image

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
e-tip
Posts: 4
Joined: 2017-09-08T06:53:55-07:00
Authentication code: 1151

One line command to distort and compose image

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

Re: One line command to distort and compose image

Post by snibgo »

e-tip wrote:is there a way to do all this work in a single command?
Yes.
snibgo's IM pages: im.snibgo.com
e-tip
Posts: 4
Joined: 2017-09-08T06:53:55-07:00
Authentication code: 1151

Re: One line command to distort and compose image

Post by e-tip »

Good to know! thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: One line command to distort and compose image

Post by snibgo »

If you show us the commands you currently use, we can show you how to combine them.
snibgo's IM pages: im.snibgo.com
e-tip
Posts: 4
Joined: 2017-09-08T06:53:55-07:00
Authentication code: 1151

Re: One line command to distort and compose image

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

Re: One line command to distort and compose image

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: One line command to distort and compose image

Post 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
e-tip
Posts: 4
Joined: 2017-09-08T06:53:55-07:00
Authentication code: 1151

Re: One line command to distort and compose image

Post by e-tip »

Oh , thanks all. Especially for the comments about my wrong commands :)
Post Reply