imagecolorset() thay đổi màu tại một chỉ số (index) cụ thể trong palette. Dùng để tạo hiệu ứng flood-fill trên ảnh palette.
Cú pháp
imagecolorset(resource $image, int $index, int $red, int $green, int $blue, int $alpha = 0): void
Tham số
- image: Resource GD (palette).
- index: Chỉ số trong palette.
- red, green, blue: RGB mới (0-255).
- alpha: Độ trong suốt (0-127, 0=đặc, 127=trong suốt).
Ví dụ
<?php
$img = imagecreate(550, 400); // palette
imagecolorallocate($img, 0, 0, 0); // màu 0: đen
$bgIndex = imagecolorat($img, 70, 85); // lấy index tại pixel (70,85)
imagecolorset($img, $bgIndex, 30, 110, 150); // đổi màu index đó thành xanh dương
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>