Noob help : fewer writes to disk

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
Qcent
Posts: 2
Joined: 2015-11-02T06:09:14-07:00
Authentication code: 1151

Noob help : fewer writes to disk

Post 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.
Qcent
Posts: 2
Joined: 2015-11-02T06:09:14-07:00
Authentication code: 1151

Re: Noob help : fewer writes to disk

Post 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.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Noob help : fewer writes to disk

Post by dlemstra »

Thanks for coming back and posting your solution. This will help future visitors :)
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply