ImagMagick:如何使用一个转换命令为图像添加渐变拼接? [英] ImagMagick: How to add a gradient splice to an image using one convert command?
问题描述
是否可以在图像底部添加渐变拼接?似乎渐变选项需要 -size,由于图像大小,我无法提供可能是varry。
Is it possible to add a gradient splice to the bottom of an image? It seems that gradient option requires -size, which I cannot provide because size of the image may varry.
转换和撰写是可能的,但我只想使用一个命令。像这样的东西(请注意,目前这是无效的):
It's possible with convert and compose but I want to use only one command. Something like this (note that this is invalid currently):
convert -fill gradient:black-white -gravity south splice 0x20 image1.jpg image2.jpg
推荐答案
- 我的建议是使用
-append
而不是-splice
。 - 图像大小可能会有所不同,但您可以通过运行
识别-format%W image1.jpg
来识别宽度。
- My suggestion to you is to use
-append
instead of-splice
. - The image size may vary, but you can recognize the width by running
identify -format %W image1.jpg
.
所以一个可能的命令来实现你想要的:
So one possible command to achieve what you want is:
convert \
input.jpg \
-size $(identify -format %W input.jpg)x20 gradient: \
-append \
output.jpg
更新:
以上命令适用于Linux,Unix或Mac OS X,但是n在Windows上。在Windows上,实现相同的最简单方法就是使用类似这两个命令的东西:
Above command works on Linux, Unix or Mac OS X, but not on Windows. On Windows, the most simple way to achieve the same you'd use something like these two commands:
for /f "usebackq delims= " %I in (`identify -format %W input.jpg`) do set width=%I
convert input.jpg -size %width%x20 gradient: -append output.jpg
以上内容适用于cmd.exe窗口中的直接执行。如果将命令放入批处理文件中,则需要修改%I
以使其 %% I
:
The above is for direct execution in a cmd.exe window. If you put the commands into a batch file, you need to modify the %I
to make it %%I
:
(对不起,我现在没有Windows系统来验证确切的语法......)
(Sorry, I don't have a Windows system around right now in order to verify the precise syntax...)
Update2:
用于Bash内联命令的Windows bat替代方案
这篇关于ImagMagick:如何使用一个转换命令为图像添加渐变拼接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!