问题
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
回答1:
- 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
Update:
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
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
:
(Sorry, I don't have a Windows system around right now in order to verify the precise syntax...)
Update2: Windows bat alternative for Bash inline command
来源:https://stackoverflow.com/questions/11828801/imagmagick-how-to-add-a-gradient-splice-to-an-image-using-one-convert-command