YouTip LogoYouTip

Php Imagecolorset

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.6; color: #333; max-width: 1200px; margin: 0 auto; padding: 20px; } h1, h2, h3 { color: #2c3e50; } a { color: #3498db; text-decoration: none; } a:hover { text-decoration: underline; } .code-block { background-color: #f8f9fa; border: 1px solid #e9ecef; border-radius: 4px; padding: 15px; overflow-x: auto; font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; font-size: 14px; line-height: 1.5; } .note { background-color: #e7f3fe; border-left: 4px solid #2196F3; padding: 15px; margin: 20px 0; } .related { margin-top: 30px; padding-top: 20px; border-top: 1px solid #eee; } .breadcrumb { margin-bottom: 20px; color: #666; } .breadcrumb a { color: #666; } .breadcrumb a:hover { color: #3498db; } .sidebar { background-color: #f8f9fa; padding: 20px; border-radius: 4px; margin-bottom: 30px; } .sidebar h3 { margin-top: 0; } .sidebar ul { list-style: none; padding-left: 0; } .sidebar ul li { margin-bottom: 8px; } .footer { margin-top: 50px; padding-top: 20px; border-top: 1px solid #eee; color: #666; font-size: 14px; } .promo { background-color: #fff8e1; padding: 15px; border-radius: 4px; margin: 20px 0; border: 1px solid #ffe082; }

PHP imagecolorset – Set Color for a Given Palette Index

imagecolorset β€” Sets the color for a given palette index.

Syntax

void imagecolorset ( resource $image , int $index , int $red , int $green , int $blue )

This function sets the specified index in the palette to the given color. It is useful for creating flood-fill-like effects in palette-based images without the overhead of actually performing a flood fill.

Note: This function is only available with the GD library.

Parameters

  • $image: An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
  • $index: The color index to set.
  • $red: The red component (0-255).
  • $green: The green component (0-255).
  • $blue: The blue component (0-255).

Return Values

Does not return a value.

Example

<?php
// Create a 100x100 image
$im = imagecreatetruecolor(100, 100);

// Allocate colors
$white = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);

// Fill the image with white
imagefill($im, 0, 0, $white);

// Set the color at index 1 to red
imagecolorset($im, 1, 255, 0, 0);

// Output the image
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>

ByteDance Coding Plan supports mainstream large models like Doubao, GLM, DeepSeek, Kimi, MiniMax. Official supply, stable and reliable. Β₯9.9/month

iFlytek Star Coding Plan includes free model call quotas, DeepSeek, GLM, Kimi, MiniMax. One-stop experience and deployment platform. Configuration Guide Β₯3.9/month Subscribe Now

← Php ImagecolorclosesthwbPhp Imagecolorclosest β†’