你如何使用ImageMagick脚本文件?

huangapple go评论54阅读模式
英文:

How do you use ImageMagick script files?

问题

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.

我目前正在尝试使用ImageMagick创建一个包含大量其他图像的图像。每个图像都有自己的裁剪值,并且在较大的图像中的位置也不同。我想一次性发送命令,而不是对输出图像进行大量读取/写入,但是命令太大,无法通过命令行传递。

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:

我找到了有关ImageMagick的一项看似未记录的功能,即脚本。但是我似乎无法弄清楚它们。请参考文档中的这个非常简单的命令:

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:

这会创建一个蓝色正方形,“粘贴” an_image.png 到上面,并将其保存为 output.png。但是我甚至使用脚本都无法重新创建这个过程:

script.mgk:

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.

尝试添加其他行会导致类似的错误。如果 an_image.png 不存在(例如),它将打印出找不到该文件的错误。

英文:

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!

答案1

得分: 2

“Scripting”功能的文档在这里

在StackOverflow上也有一些示例,例如这里这里以及其他地方。

具体来说,在命令行上,最后一项被假定为文件名,结果会被写入那里。然而,在使用脚本接口时,没有这样的假设,如果你想创建一个文件,你需要使用 -write filename。你应该能在引用的示例中看到这一点。

所以,具体来说,将你的脚本更改为:

-size 50x50 xc:skyblue
an_image.png -composite
-write output.png
英文:

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

huangapple
  • 本文由 发表于 2023年5月29日 15:48:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355532.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定