Gradient map effect in PHP without additional packages?

I know that Imagemagick can achieve the effect of a gradient map by converting the image to grayscale, then creating a gradient and performing the conversion of the Color View table.

What interests me is if the default image functions of PHP can take a full-color image and turn it into a duot.

IMG_FILTER_COLORIZE will work if it allows me to specify two colors!

+4
source share
1 answer

If you want to get a gradient map effect. The procedure is as follows:

Luma = 0.2126 * R + 0.7152 * G + 0.0722 * B

  1. Once you have your brightness, you must create a function to display the brightness from 0 ~ 100% to the color gradient you want from 0% to 100% ... In other words:

luma = 0% → color A

luma = 100% → color B

luma = X% → interpolation between A and B ... InterpolatedColor = X% * B + (100 - X)% * A

Of course, apply this formula for all channels R, G, and B.

This can be done easily in PHP as soon as you get access to the image pixels.

+1
source

All Articles