Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

RGB

RGB is an additive color model in which a color is produced by combining three channels of light: red, green, and blue. Each channel usually holds an integer between 0 and 255, giving 16,777,216 possible colors.

PHP’s gd extension works natively with RGB: imagecolorallocate() takes three integers, one per channel, and returns a color identifier that can then be used to draw on an image. RGB values are also commonly written in hexadecimal notation, #RRGGBB, as used in CSS and HTML.

RGBA extends the model with a fourth, alpha channel, controlling transparency.

<?php

    $image = imagecreatetruecolor(100, 100);
    $red = imagecolorallocate($image, 255, 0, 0);
    imagefill($image, 0, 0, $red);

?>

Documentation

See Also