How to apply saturation to photo using php gd

903 views Asked by At

I want to apply saturation to photo using php gd but I only know that to do image editing. I need to:

  1. Change BGR to HSL
  2. do something which I don't know.
  3. Change the result back from HSL to BGR.

Anyone know what is the logic/algorithm for step 2? And is there any other better way to apply saturation to photo in php?

Edit: What I mean by "apply saturation" is manipulating/changing saturation of photo like how you can do in most of the image editing tool like ipiccy.com and edit photo function in Microsoft office 2010 where you can change value of slider and then saturation of photo will change. I want to write code in php to change saturation of photo but I have no clue how to start. Anyone can advise? Thank you.

1

There are 1 answers

0
Mehran On

If you are looking for any transformation, you can simply apply one simple curve to your saturation channel. And since it's not important what transformation you are applying, you can use a simple x^0.5 curve.

Take a look at this wikipedia entry for more information on curves.

And if you wonder how to implement a x^0.5 curve, here it is. Considering saturation as a byte ranging from 0 to 255:

Satu[x, y] = (int)(sqrt(Satu[x, y] / 255.0) * 255.0);