Use the imagecolorallocate () function to set the color for PHP image processing. imagecolorallocate_PHP tutorial

Source: Internet
Author: User
For PHP image processing, use the imagecolorallocate () function to set the color example, imagecolorallocate. For PHP image processing, use the imagecolorallocate () function to set the color. imagecolorallocate dynamically outputs beautiful images using PHP, but cannot do without the color setting, for example, you can use the imagecolorallocate () function to set the color for PHP image processing.

While using PHP to dynamically output beautiful images, it is also inseparable from color settings, just like using a color palette for painting. To set the image color, call the imagecolorallocate () function. If you need to set multiple colors in the image, you only need to call this function multiple times. The function is prototype as follows:

The code is as follows:


Int imagecolorallocate (resource $ image, int $ red, int $ green, int $ blue) // assign color to an image


This function returns an identifier representing the color composed of a given RGB component. The $ red, $ green, and $ blue parameters are the red and green colors required. These parameters are integers from 0 to 255 or hexadecimal values 0 × 00 to 0xFF. The 1st parameter $ image is the handle of the canvas image. this function must call the color in the image represented by $ image. However, if you use the imagecreate () function to create a canvas, the first call to the imagecolorallocate () function will fill the background color with the image based on the color palette. The code for using this function is as follows:

The code is as follows:


<? Php
$ Im = imagecreate (100,100); // provides a canvas resource for the color setting function.
// Set the background to red
$ Background = imagecolorallocate ($ m, 255, 0, 0); // The first call sets the background color for the canvas.
// Set some colors
$ White = imagecolorallocate ($ im, 255,255,255); // returns an identifier that is white as a decimal integer.
$ Black = imagecolorallocate ($ im, 0); // return the identifier set to black by the decimal parameter
// Hexadecimal mode
$ White = imagecolorallocate ($ im, 0xFF, 0xFF, 0xFF); // returns an identifier that is white as a hexadecimal integer.
$ Black = imagecolorallocate ($ im, 0 x, 0 x, 0x00); // returns an identifier that is set to black by a hexadecimal integer.
?>

In the example of setting the color by using the trim () function, imagecolorallocate dynamically outputs beautiful images using PHP, while also inseparable from the color settings, just like painting...

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.