Generate Gradient size based on existing image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ziongates
Posts: 2
Joined: 2014-09-22T19:05:41-07:00
Authentication code: 6789

Generate Gradient size based on existing image

Post by ziongates »

Greetings Gurus,

I have a command line which works fine except for the hardcoded image size. It overlays a gradient onto an image.
How can the command dynamically generate the Gradient Size automatically based on the current image being processed ("%x") ?

This is the windows command line.

composite.exe -compose Dst_In "%x" ( -size 24x24 gradient:black-white -alpha Set ) png32:"%x"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generate Gradient size based on existing image

Post by fmw42 »

You need to use -sparse-color barycentric. See http://www.imagemagick.org/Usage/canvas ... _gradients

In unix syntax, it would be

Code: Select all

convert image \
\( -clone 0 -sparse-color Barycentric '0,0 white  0,%[fx:h-1] black' \) \
...

In windows, I believe it would be

Code: Select all

convert image ^
( -clone 0 -sparse-color Barycentric '0,0 white  0,%[fx:h-1] black' ) ^
...
The code in parenthesis will create the gradient.

The following ... means put whatever code you want. If you want to do compositing, you probably need to use the convert -compose composemethod -composite style syntax. See http://www.imagemagick.org/Usage/compose/
ziongates
Posts: 2
Joined: 2014-09-22T19:05:41-07:00
Authentication code: 6789

Re: Generate Gradient size based on existing image

Post by ziongates »

Thanks Fred, that's it!
Post Reply