rokka-io / imagine-vips

libvips adapter for php imagine
https://rokka.io
Other
41 stars 8 forks source link

speedup for generateImage #2

Closed jcupitt closed 6 years ago

jcupitt commented 6 years ago

generateImage has:

        // 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())]);
chregu commented 6 years ago

Thanks a lot. Integrated that.