I'm currently trying to create an image with a very large number of other images using ImageMagick. Each image has its own crop values, and placement within the larger image. Rather than a large number of read/writes to the output image, I'd like to send the command all at once, but it is far too large to pass via the command line.
I've found references to a seemingly undocumented feature of ImageMagick, scripts. However I can't seem to figure them out. Take this very simple command from the docs:
magick -size 50x50 xc:skyblue an_image.png -composite output.png
This creates a blue square, "pastes" an_image.png
onto it, and saves it as output.png
. However I'm struggling to recreate even this with a script:
script.mgk:
-size 50x50 xc:skyblue an_image.png -composite output.png
command:
magick -script script.mgk
The above outputs the error:
magick: unable to open image 'output.png': No such file or directory @ error/blob.c/OpenBlob/3569.
Trying additional lines yields similar errors. Though if an_image.png
doesn't exist (for example) it will instead print an error saying that that file couldn't be found.
Any help is greatly appreciated!
The scripting feature is documented here.
There are a few examples on StackOverflow too, e.g. here , here and others.
Specifically, on the command line, the last item is assumed to be a filename and the results get written there. When using the script interface, however, there is no such assumption, and you need -write filename
if you want a file created. You should be able to see that in the cited examples hopefully.
So, in concrete terms, change your script to:
-size 50x50 xc:skyblue
an_image.png -composite
-write output.png