Graphicsmagick composite and cropping on the same team

I need to get a specific crop of an image and put it on another image in a specific place and resize.

I can crop the first image and save it in a file in one command, and then I can collect two images in another command. However, I would like to do this in one team - is this possible with graphics and how?

Here are two commands that I use atm:

gm convert -crop 1457x973+254+413 amber.jpg tmp.jpg gm composite -geometry 6000x4000+600+600 tmp.jpg lux_bg.png out.jpg 

The reason for this is to refuse to write to disk, and then read again when all this can be done in memory. For example, with ImageMagick, the same commands will be written to the same command as follows:

 convert lux_bg.png \( amber.jpg -crop 1457x973+254+413 \) -geometry 6000x4000+600+600 -composite out.jpg 

I am doing this with ImageMagick, but would like to do it with GraphicsMagick.

+6
source share
2 answers

If your reason is simply to avoid creating a temporary file , you can still do it with two commands by building pipelines (a wonderful concept created by afaik , Douglas McIlroy around 1964):

 gm convert -crop 1457x973+254+413 amber.jpg - | gm composite -geometry 6000x4000+600+600 - lux_bg.png out.jpg 
hint

: pay attention to two lines - in two teams, and the pipe |

since - can be used to indicate standard output and input in two commands, respectively.

This means that the file is not created, everything must happen in memory.

You can find this in the help ( gm -help convert | grep -i -e out -B 1 ):

Specify "file" as "-" for standard input or output.

Usage - is common for unix-like and should be inspired by the POSIX Utility Syntax Guide .

+3
source

Have you tried the && operator? Your team should become:

 gm convert -crop 1457x973+254+413 amber.jpg tmp.jpg && gm composite -geometry 6000x4000+600+600 tmp.jpg lux_bg.png out.jpg 
0
source

Source: https://habr.com/ru/post/957496/


All Articles