ImagMagick: How to add gradient splicing to an image with a single convert command?

Can I add a gradient round to the bottom of the image? It seems that the gradient parameter requires a -size that I cannot provide, since the size of the image may vary.

This is possible with conversion and layout, but I want to use only one command. Something like this (note that this is not currently valid):

convert -fill gradient:black-white -gravity south splice 0x20 image1.jpg image2.jpg 
+1
source share
1 answer
  • My suggestion for you is to use -append instead of -splice .
  • Image size may vary, but you can recognize the width by running identify -format %W image1.jpg .

So, one possible command to achieve the desired:

 convert \ input.jpg \ -size $(identify -format %W input.jpg)x20 gradient: \ -append \ output.jpg 

Update:

The above command works on Linux, Unix or Mac OS X, but not on Windows. On Windows, the easiest way to achieve the same thing would be to 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 the cmd.exe window. If you put the commands in a batch file, you need to change %I to make it %%I :

(Sorry, I don’t have a Windows system right now to check the exact syntax ...)

Update2: Windows bat alternative for Bash built-in command

+1
source

All Articles