General Ramps

Some days we just wake up wanting a linear blend from chartreuse rgb(127, 255, 0) to cornflower blue rgb(100, 149, 235). Remember, there is no accounting for taste around here. Oh, and we want it at 59.127º, please, and in an image 270 by 312 pixels.

David Tschumperlé furnished us with the general technique, for which we are grateful. For those of you who'd like to add a "-general_ramp" command to your local gmic command files, you can get a suitably formatted script here.

A few matters of note:

  1. The ramp itself begins life as a grayscale image and occupies the initial position of the image list. It will serve in short order as a mask to the -image command.
  2. The starting chartreuse and ending cornflower blue colors commence as single pixel, three channel images, each conjured from variants of the -input command's image stream notation. See the resize gradient technique in this recipe.
  3. The script harnesses the -resize command to scale these one pixel sized "color swatches"  to match the dimensions of the gray scale ramp. This leaves the gray scale ramp at position zero ([0]) in the image list, the solid cornflower blue swatch at position one ([1]) and the solid chartreuse swatch at position two ([2]).
  4. The -image command serves in this example as a compositor. Operating on the chartreuse swatch, it places the "sprite", the cornflower blue swatch, at pixel coordinate 0,0,0,0 — the northwest image corner — using full opacity (1). In this variant, the grayscale ramp is operating as a mask, gradually attenuating the cornflower blue sprite so that the underlying chartreuse shows through.
gmic -debug \
   ang='pi*59.127/180' \
   rw=270 \
   rh=312 \
   '$rw','$rh',1,1,'x*cos($ang)+y*sin($ang)' \
   -normalize 0,1 \
  '(100^149^235)' \
  '(127^255^0)' \
  -resize[-2,-1] [-3],[-3],1,3 \
  -image[-1] [-2],0,0,0,0,1,[-3] \
  -rm[-3,-2]

Resizing One Dimensional Functions