Page 1 of 1

Noob help : fewer writes to disk

Posted: 2015-11-02T06:44:43-07:00
by Qcent
In a perl script I need to take 2 images crop them. position them on a canvas and then overlay a third image.
i have accomplished this with 5 system calls and a 6th one to clean up the files.

Code: Select all

	### Crop Bottom 
system("/usr/local/bin/convert  path/to/bot.png'[1920x1080]'  -crop 1920x1017+0+0  path/to/b.png");

	### Crop Top 
system("/usr/local/bin/convert  path/to/top.png'[1920x1080]'  -crop 1920x690+0+0  path/to/t.png");

	###Position Bottom of Image
system("/usr/local/bin/composite -gravity SouthWest  path/to/b.png  path/to/ovrlay.png  path/to/x.png");

	###Position Top of Image
system("/usr/local/bin/composite -gravity NorthWest  path/to/t.png  path/to/x.png  path/to/y.png");

	###Overlay Frame
system("/usr/local/bin/composite -gravity NorthWest  path/to/ovrlay.png path/to/y.png  path/to/output.jpg");

	###CleanUp Temp files
system("rm path/to/*.png");
i would like to do this in as few steps as possible with only one write to disk. something like

Code: Select all

composite -gravity NorthWest  path/to/ovrlay.png  \(composite -gravity NorthWest \(convert path/to/top.png'[1920x1080]'  -crop 1920x690+0+0\) \(composite -gravity SouthWest \(convert path/to/bot.png'[1920x1080]'  -crop 1920x1017+0+0\) path/to/ovrlay.png \) \) path/to/output.jpg
but that is producing many errors. what is the proper syntax for combining multiple commands.

Re: Noob help : fewer writes to disk

Posted: 2015-11-02T10:50:26-07:00
by fmw42

Re: Noob help : fewer writes to disk

Posted: 2015-11-03T07:12:25-07:00
by Qcent
Thank you for pointing me in the right direction. i re-read those sections more carefully and came up with this:

Code: Select all

 convert  -size 1920x1418 xc:skyblue \
\(  /path/to/bot.png'[1920x1080]'  -crop 1920x1017+0+0 \) -gravity SouthWest  -composite -gravity NorthWest \
\(  /path/to/top.png'[1920x1080]'  -crop 1920X690+0+0  \)  -composite \
\(  /path/to/ovrlay.png \)  -composite \
\
/path/to/output.jpg
Works perfectly and is 8 times faster then the disk writes. Praised be the devs.

Re: Noob help : fewer writes to disk

Posted: 2015-11-03T07:33:02-07:00
by dlemstra
Thanks for coming back and posting your solution. This will help future visitors :)