ImagMagick: How to add a gradient splice to an image using one convert command?

浪尽此生 提交于 2019-12-10 11:39:58

问题


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:


  1. My suggestion to you is to use -append instead of -splice.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!