Skip to content

Colourspace conversion for gradient creation #130

Closed
@jarodium

Description

@jarodium

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

  1. sRGB2scRGB
  2. scRGB2XYZ
  3. 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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions