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 » 2017-09-08T07:13:37-07:00

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: 9402
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 » 2017-09-08T07:42:20-07:00

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 » 2017-09-08T08:12:44-07:00

Good to know! thanks

snibgo
Posts: 9402
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 » 2017-09-08T08:20:58-07:00

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 » 2017-09-08T08:40:26-07:00

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: 9402
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 » 2017-09-08T09:12:05-07:00

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: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: One line command to distort and compose image

Post by fmw42 » 2017-09-08T09:53:43-07:00

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 » 2017-09-11T00:10:07-07:00

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

Post Reply