ImageMagick 命令行选项顺序(和命令行参数的类别) [英] ImageMagick Command-Line Option Order (and Categories of Command-Line Parameters)

查看:39
本文介绍了ImageMagick 命令行选项顺序(和命令行参数的类别)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主管要求我将使用 PerlMagick 的 Perl 脚本部分转换为管道和使用 ImageMagick 的命令行版本(出于各种不相关的原因).

My supervisor has asked me to convert the parts of our Perl scripts that use PerlMagick to instead pipe and use the command line version of ImageMagick (for various unrelated reasons).

使用我们现有的界面(裁剪、缩放、保存等),我正在构建用户想要对图像执行的操作列表,构建语句以进行管道传输,然后执行它.

Using the our existing interface (crop, scale, save, etc) I'm building up a list of operations the user wants to perform on an image, constructing the statement to pipe and then executing it.

我想知道的是:

  1. 转换操作是从左到右执行的吗?即我通过它们的顺序
  2. 如果我两次传递相同的选项会怎样?它们是分开进行的吗?

显然,对图像执行操作的顺序至关重要,因此我正在尝试确定是否可以一次性执行所有操作(可能会提高效率?)必须单独执行每个操作.谢谢

Obviously the order in which operations are performed on an image is vital, so I'm trying to work out if I can perform all of the operations in one go (possibly gaining efficiency?) or if it I'm going to have to perform each operation separately. Thanks

推荐答案

不幸的是,这个问题的公认答案尚未完成... :-)

Unfortunately, the accepted answer to this question is not yet complete... :-)

假设你的 ImageMagick 版本是最近的,这里是一个重要的修改:

Assuming, your ImageMagick version is a recent one, here is an important amendment to it:

  • 您应该区分 3 类主要的命令行参数:

  • you should differentiate between 3 major classes of command line parameters:

  1. 图片设置
  2. 图像运算符
  3. 图像序列运算符
     

这三个类的行为确实不同:

These three classes do behave differently:

  1. 图片设置

  1. 图像设置在命令行中出现时仍然存在.它可能会影响所有后续处理(但不会影响之前的处理):

  1. An image setting persists as it appears on the command line. It may affect all subsequent processing (but not previous processing):

  • 处理,例如稍后在命令行中读取一个或多个图像;
  • 由以下图像操作员完成的处理;
  • 通过写入图像作为输出进行处理.
     

图像设置保持有效...

  • ...直到它被重置或被相同类型的不同设置替换,
  • ...或者直到命令行终止.
     

  • 图像运算符

    1. 一个图像运算符被应用于(单个)图像并被遗忘.它不同于图像设置,因为它会在图像出现在命令行时立即影响图像.(请记住:一个图像设置会一直存在,直到命令行终止,或者直到它被重置.)

    1. An image operator is applied to a (single) image and forgotten. It differs from an image setting because it affects the image immediately as it appears on the command line. (Remember: an image setting which persists until the command line terminates, or until it is reset.)

    如果您需要将相同的图像运算符应用于同一命令行中的第二个图像,则必须在命令行上重复该运算符.

    If you need to apply the same image operator to a second image in the same commandline, you have to repeat that exact operator on the commandline.

    严格来说,按照ImageMagick命令行的新架构,所有的图像operators都应该在它要加载的图像之后写入.然而,IM 开发者妥协了:为了向后兼容,图像操作符仍然可以在加载图像之前出现——然后它们将应用于它们可用的第一个图像.

    Strictly speaking, in compliance with the new architecture of ImageMagick command lines, all image operators should be written after the loading of the image it is meant for. However, the IM developers compromised: in the interest of backward compatibility, image operators can still appear before loading an image -- they will then be applied to the first image that is available to them.

  • 图像序列运算符

    1. 图像序列运算符应用于所有当前加载的图像(然后被遗忘).

    1. An image sequence operator is applied to all currently loaded images (and then forgotten).

    它与简单的图像操作符的不同之处在于它不仅影响单个图像.(有些操作符只有在他们的操作有多个图像供消费时才有意义:想想-append-combine-composite-morph...)

    It differs from a simple image operator in that it does not only affect a single image. (Some operators only make sense if their operation has multiple images for consumption: think of -append, -combine, -composite, -morph...)

  • 从上面的原则你已经可以得出结论:命令行参数的顺序在大多数情况下很重要.(如果你知道他们做什么,你也知道你需要使用什么顺序来应用它们.)

    From above principles you can already conclude: the order of the command line parameters is significant in most cases. (If you know what they do, you also know which order you need to use applying them.)

    (为了完整起见,我应该补充:还有另一类 miscellaniousother 参数,它们不属于上面列出的任何类别.想想-debug-verbose-version.)

    (For completeness' sake I should add: there is another class of miscellanious, or other parameters, which do not fall into any of the above listed categories. Think -debug, -verbose or -version.)

    不幸的是,IM 命令行参数的 3 类之间的明确区别在(否则非常精明的)IM 用户中还不是常识.因此,获得更多曝光是值得的.

    Unfortunately, the clear distinction between the 3 classes of IM command line paramaters is not yet common knowledge among (otherwise quite savvy) IM users. So it merits to get much more exposure.

    这种明显的区别是在 ImageMagick 主要版本 6 中引入的.在此之前,它更令人困惑:一些设置的语义随着上下文及其给出的顺序而改变.复杂命令的结果并不总是可预测的,有时令人惊讶和不合逻辑.(现在它们有时也可能令人惊讶,但是当您仔细观察它们时,理解上述内容时,它们总是很合乎逻辑.)

    This clear differentiation was introduced with ImageMagick major version 6. Before, it was more confusing: some settings' semantics changed with context and also with the order they were given. Results from complex commands were not always predictable and sometimes surprising and illogical. (Now they may be surprising too sometimes, but when you closely look at them, understanding the above, they are always quite logical.)

    当您不确定某个特定参数属于哪个类时,请运行

    Whenever you are not sure, which class one particular parameter belongs to, run

     convert -help | less
    

    搜索您的参数.找到后,向后滚动:然后您应该找到它出现的标题".现在您可以确定它是哪种类型:Image SettingImage OperatorImage Sequence Operator -- 并考虑我在上面所说的.

    Search for your parameter. Once found, scroll back: you should then find the "heading" under which it appears. Now you can be sure which type it is: an Image Setting, an Image Operator, or an Image Sequence Operator -- and take into account what I've said about them above.

    如果你的工作是将你的 ImageMagick 界面从 PerlMagick 移植到 CLI,你应该知道另一个技巧:你可以插入

    If your job is to port your ImageMagick interface from PerlMagick to CLI, you should be aware of one other trick: You can insert

     +write output-destination
    

    命令行上的任何地方(甚至多次).然后,这会将当前加载的图像(或当前加载的图像序列)以其当前处理状态写出到给定的输出目的地.(把它想象成类似于 tee-shell/终端使用的命令,它重定向 <stdout> 进入一个文件.) 输出目的地可以是一个文件,或者 show: 或任何其他对 IM 输出有效的东西.写入输出后,将继续处理完整命令.

    anywhere on the command line (even multiple times). This will then write out the currently loaded image (or the currently loaded image sequence) in its currently processed state to the given output destination. (Think of it as something similar as the tee-command for shell/terminal usage, which re-directs a copy of <stdout> into a file.) Output destination can be a file, or show: or whatever else is valid for IM outputs. After writing to the output, processing of the complete command will continue.

    当然,只有在第一个(或任何其他)图像运算符之后插入 +write 才有意义——否则当前图像列表不会改变.

    Of course, it only makes sense to insert +write after the first (or any other) image operator -- otherwise the current image list will not have changed.

    如果有多个输出图像(因为当前图像列表包含多个图像),那么ImageMagick会自动为各自的文件名分配索引号.

    Should there by multiple output images (because the current image list consists of more than one image), then ImageMagick will automatically assign index numbers to the respective filename.

    这对调试(或优化、精简、简化...)复杂的命令设置有很大帮助.

    This is a great help with debugging (or optimizing, streamlining, simplifying...) complex command setups.

    这篇关于ImageMagick 命令行选项顺序(和命令行参数的类别)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆