// Make a 1x1 pixel with the red channel and cast it to provided format.
$pixel = VipsImage::black(1, 1)->add($red)->cast(BandFormat::UCHAR);
// Extend this 1x1 pixel to match the origin image dimensions.
$vips = $pixel->embed(0, 0, $width, $height, ['extend' => Extend::COPY]);
$vips = $vips->copy(['interpretation' => self::getInterpretation($color->getPalette())]);
// Bandwise join the rest of the channels including the alpha channel.
$vips = $vips->bandjoin([
$green,
$blue,
$alpha,
]);
You can make this a bit quicker. The add() method can take an array, so you can skip the final bandjoin():
// Make a 1x1 pixel with the red channel and cast it to provided format.
$pixel = VipsImage::black(1, 1)->add([$red, $green, $blue, $alpha])->cast(BandFormat::UCHAR);
// Extend this 1x1 pixel to match the origin image dimensions.
$vips = $pixel->embed(0, 0, $width, $height, ['extend' => Extend::COPY]);
$vips = $vips->copy(['interpretation' => self::getInterpretation($color->getPalette())]);
generateImage
has:You can make this a bit quicker. The
add()
method can take an array, so you can skip the finalbandjoin()
: