PHP image processing using the Imagecolorallocate () function to set color examples _php Tips

Source: Internet
Author: User

In the use of PHP dynamic output beautiful images, but also inseparable from the setting of colors, like painting when you need to use the same color palette. To set the color of the image, you need to call the Imagecolorallocate () function to complete. If you need to set a variety of colors in the image, just call the function multiple times. The prototype of the function looks like this:

Copy Code code as follows:

int Imagecolorallocate (resource $image, int $red, int $green, int $blue)//Assign color to a picture

The function returns an identifier that represents the color composed of the given RGB component. Parameter $red, $green and $blue are the red, green and blue components of the desired color respectively. These parameters are integers from 0 to 255 or hexadecimal 0x00 to 0xFF. The 1th parameter $image is a handle to the canvas image that must call the color in the image represented by $image. Note, however, that if the canvas is created using the Imagecreate () function, the first call to the Imagecolorallocate () function fills the background color with the palette-based image. The use code for the function is as follows:
Copy Code code as follows:

<?php
$im = Imagecreate (100,100);//provide a canvas resource for setting color functions
Background set to Red
$background = Imagecolorallocate ($m, 255,0,0);//First call to set the background color for the canvas
Set some colors
$white = Imagecolorallocate ($im, 255,255,255);//Returns an identifier that is set to White by a decimal integer
$black = Imagecolorallocate ($im, 0,0,0)//Returns an identifier set to Black by the decimal parameter
Hexadecimal mode
$white = Imagecolorallocate ($im, 0xff,0xff,0xff);//Returns an identifier set to white by a hexadecimal integer
$black = Imagecolorallocate ($im, 0x00,0x00,0x00);//Returns an identifier set to black by a hexadecimal integer
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.