Weighted Multi-Color Gradients to Mimic CSS Gradients
Posted: 2011-11-11T13:12:16-07:00
I'd like to create weighted, multi-color gradients to match those that can be created using CSS3.
I know it's possible to create a simple two-color gradient as described in the docs at http://www.imagemagick.org/Usage/canvas/#gradient. What I'm not sure about is how to make more than two colors where each color can be placed at a specific percentage (for weighting).
I know I can use ImageMagick to create a two-color gradient, with one color at the 0,0 and the other color at the [100% width],0. For example, this command:
will produce the same gradient as this CSS:
Specifically, I'd like to use ImageMagick to create a gradient image matching the gradient a browser would render for the following CSS:
This CSS gradient differs from the top CSS gradient in two ways:
1. This gradient has three colors instead of two, and
2. The color stops in this gradient are not evenly spaced.
An example of the above can be seen here in Chrome/Safari or Firefox: http://jsfiddle.net/aMhL8/
Ideally, I'd be able to use an arbitrary number of colors (three was just a simple example). Does anyone know how to accomplish this with ImageMagick? Any help would be greatly appreciated.
I know it's possible to create a simple two-color gradient as described in the docs at http://www.imagemagick.org/Usage/canvas/#gradient. What I'm not sure about is how to make more than two colors where each color can be placed at a specific percentage (for weighting).
I know I can use ImageMagick to create a two-color gradient, with one color at the 0,0 and the other color at the [100% width],0. For example, this command:
Code: Select all
convert -size 100x500 gradient:'#f00-#00f' gradient-2.png
Code: Select all
#gradient {
width: 100px;
height: 500px;
background-image: -webkit-linear-gradient(top, #f00, #00f);
}
Code: Select all
#gradient {
width: 100px;
height: 500px;
background-image: -webkit-linear-gradient(top, #f00 10%, #ff0 20%, #00f 80%);
}
1. This gradient has three colors instead of two, and
2. The color stops in this gradient are not evenly spaced.
An example of the above can be seen here in Chrome/Safari or Firefox: http://jsfiddle.net/aMhL8/
Ideally, I'd be able to use an arbitrary number of colors (three was just a simple example). Does anyone know how to accomplish this with ImageMagick? Any help would be greatly appreciated.