imagecolorallocate() cấp phát màu RGB cho ảnh GD (palette hoặc true color). Màu đầu tiên cấp phát trở thành background color của ảnh palette.
Cú pháp
imagecolorallocate(resource $image, int $red, int $green, int $blue): int|false
Ví dụ: Tạo ảnh nền màu xanh dương
<?php
$img = imagecreatetruecolor(600, 220);
$bg = imagecolorallocate($img, 20, 50, 120);
imagefill($img, 0, 0, $bg);
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>