Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

graphicsmagick composite and crop in the same command

I need to get a specific crop of an image and put it over another image at a certain position and resized.

I can crop the first image and save it to a file in one command and then I can composite the 2 images in another command. However, I would like to do it in a single command - is this possible with graphicsmagick and how?

Here are the 2 commands I am using 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 wanting this is to avoid writing to disk then reading again when all this could be done in memory. With ImageMagick, for example, the same 2 commands would be written in a single command like this:

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

I am doing this with ImageMagick for now but would love to do it with GraphicsMagick.

like image 532
Dan Caragea Avatar asked Nov 06 '13 11:11

Dan Caragea


1 Answers

If your reason is simply to avoid creating a temporary file, you can still do it with two commands by constructing 'pipelines' (a great concept invented 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: note the two - dashes in the two commands, and the | pipe

since the - can be used to mean the standard output and input in the two commands respectively.

This means that no file is created, all should happen in the 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.

The use of - is common in unix-likes and must have been inspired by, or by something related to, the POSIX standard's Utility Syntax Guidelines.

like image 128
n611x007 Avatar answered Oct 01 '22 11:10

n611x007