Description
Hello,
I'm trying to create a user input gradient, in which, the user feeds html's hexcodes and then the software generates a gradient.
I one of the issues here i've found the following code:
function fxGradient($start,$stop) {
$lut = \Jcupitt\Vips\Image::identity()->divide(255);
// lut * stop + (1 - lut) * start
$lut = $lut->multiply($stop)
->add($lut->multiply(-1)->add(1)->multiply($start));
$lut = $lut->colourspace('srgb', ['source_space' => 'lab']);
return $lut;
}
In which I call like this:
$corstart = parse("#000000"); //returns [0,0,0]
$corstop = parse("#FF0000"); //returns [255,0,0]
$image = $this->image->maplut(fxGradient($corstart, $corstop));
in which, my start and stop codes are rgb triples [0,0,0] and [255,0,0] which I got from @kleisauke 's useful parse function.
I figure I should make use of
- sRGB2scRGB
- scRGB2XYZ
- XYZ2Lab
in that particular order.
I would like to ask if there is an easier way to create a gradient of RGB colors and choose the amount of start color ( I suspect I should play with the add function a bit ) , this, while avoiding colorspace conversion.
Best regards
PS: I would like to also like to suggest opening up "Discussions" for the community to trade ideas... I'm starting to feel heavy conscience of having my questions here as issues :)