Hi everyone i have an image ( it's a book cover ) that is composed by back, spine, and cover like in this 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
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
One line command to distort and compose image
-
- 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
Yes.e-tip wrote:is there a way to do all this work in a single command?
snibgo's IM pages: im.snibgo.com
Re: One line command to distort and compose image
Good to know! thanks
-
- 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
If you show us the commands you currently use, we can show you how to combine them.
snibgo's IM pages: im.snibgo.com
Re: One line command to distort and compose image
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
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
-
- 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
Your final command should have "-geometry" after the inputs, and "-composite" after that, like this:
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.
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:
I don't know what "-matte" does or used to do. I suggest you use only documented operations and settings.
Code: Select all
convert cover.png spine.png -geometry +0+0 -composite composed_cover.png
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 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
snibgo's IM pages: im.snibgo.com
- 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
It was the very old form of -alpha on/set. +matte was the old form of -alpha off.snibgo wrote:I don't know what "-matte" does or used to do. I suggest you use only documented operations and settings.
So he has redundant commands of -matte -alpha set
Re: One line command to distort and compose image
Oh , thanks all. Especially for the comments about my wrong commands