Tuesday, 8 April 2014

truecolours colour

Truecolor color handling
 

For Truecolor images the colors are actually simple 31-bit longs. Or, think of them as being
composed of 4 bytes arranged like this:


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.
 

For example:
<?
$im = ImageCreateTruecolor(400,300);
ImageFilledRectangle($im,0,0,399,299,0x00ffffff);
ImageFilledEllipse($im,200,150,300,300,0x00000000);
ImageAlphaBlending($im,true);
ImageFilledRectangle($im,100,0,400,100,0x60ff1111);
ImageFilledRectangle($im,100,100,400,200,0x30ff1111);
ImageFilledRectangle($im,100,200,400,300,0x10ff1111);
Header('Content-Type: image/png');
ImagePNG($im);
?>
 

Output:
 

This example could also be written like this:
<?php
$im = ImageCreateTruecolor(400,300);
$white = ImageColorAllocate($im,255,255,255);
ImageFilledRectangle($im,0,0,399,299,$white);
$black = ImageColorAllocate($im,0,0,0);
ImageFilledEllipse($im,200,150,300,300,$black);
ImageAlphaBlending($im,true);
$col = ImageColorResolveAlpha($im,0xff,0x11,0x11,0x60);
ImageFilledRectangle($im,100,0,400,100,$col);
$col = ImageColorResolveAlpha($im,0xff,0x11,0x11,0x30);
ImageFilledRectangle($im,100,100,400,200,$col); $col = ImageColorResolveAlpha($im,0xff,0x11,0x11,0x10


); - 23 -
 

ImageFilledRectangle($im,100,200,400,300,$col);
Header('Content-Type: image/png');
ImagePNG($im);
?>

                                            "News powered by"




No comments:

Post a Comment

About Me

Popular Posts

Designed By Seo Blogger Templates