Color Handling using PHP -- Paint colors

Paint Colors

You can actually paint colors with color handling methods.

Color Handling

For images with an 8-bit indexed palette it can be tricky to manage colors (paint colors).
Output
paint colors
For paletted images the following functions can be useful:
  • ImageColorClosest
  • ImageColorExact
  • ImageColorDeallocate
For Truecolor images we have no such issues.
Output:
paint colors

Truecolor

For Truecolor images the colors are actually simple 31-bit longs. Or, think of them as being composed of 4 bytes arranged like this:
truecolor
The highest or leftmost bit in the alpha channel is not used which means the alpha channel can only have values from 0 to 127. You can use the ImageColorAllocate() as with paletted images, but you can also specify the color directly.

Example

Output:
color Handling
This example could also be written like this:
Given the nature of the way truecolor colors are constructed, we can rewrite our color testing strip using PHP’s bitshift operator:
Output:
truecolor handling

0 comments:

Post a Comment

www.comhttp.blogspot.in. Powered by Blogger.