PHP image processing using imagecolorallocate () function set color example, imagecolorallocate_php tutorial

Source: Internet
Author: User

PHP image processing using the Imagecolorallocate () function to set the color example, imagecolorallocate


The use of PHP to dynamically output beautiful images, but also inseparable from the color settings, like painting when you need to use a palette. To set the color of the image, you need to call the Imagecolorallocate () function to complete. If you need to set multiple colors in the image, just call the function multiple times. The prototype of the function is as follows:
Copy the 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 a color made up of a given RGB component. The parameters $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 the handle to the canvas image, which must call the color in the image represented by $image. Note, however, that if you are using the Imagecreate () function to create a canvas, the first call to the Imagecolorallocate () function will populate the color palette-based image with the background color. The usage code for this function is as follows:
Copy the Code code as follows:
<?php
$im = Imagecreate (100,100);//provide a canvas resource for setting the color function
Background set to Red
$background = Imagecolorallocate ($m, 255,0,0);//The background color of the canvas is set for the first call
Set some colors
$white = Imagecolorallocate ($im, 255,255,255);//Returns an identifier 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
?>

http://www.bkjia.com/PHPjc/914044.html www.bkjia.com true http://www.bkjia.com/PHPjc/914044.html techarticle PHP image processing using the Imagecolorallocate () function set color example, imagecolorallocate in the use of PHP dynamic output beautiful images, but also inseparable from the color settings, like painting ...

  • Related Article

    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.