Imagecreatetruecolor() PHP Function

PHP Imagecreatetruecolor() Function Generates 24-Bit Color Images

The imagecreatetruecolor() function is used in PHP to create a new true color image using the GD Library. True color uses a 24-bit color depth when displaying an RGB image. Its two parameters are the width and height of the image you are creating.

Sample Code Using Imagecreatetruecolor() Function

This code generates a PNG image that is 130 pixels wide by 50 pixels high. The imagecreatetruecolor() function specifies a shape that is 130 pixels wide by 50 pixels high.

The text color is set using RGB values. The text that will print on the shape is "A Simple Text String," in size 1 (of 1-5) with an x ordinate of 5 and a y-ordinate of 5.

Return Values

When successful, this function returns an image identifier that represents a black image of the specified size. If not successful, it returns "False."

Considerations

The GD library must be enabled for this function to work properly; otherwise, the return value is False. It can be downloaded free from the internet if you don't already have it installed.

Imagecreatetruecolor() vs. Imagecreate() Function

Although the imagecreate() function still works in PHP, the PHP manual recommends the use of the newer imagecreatetruecolor() function, which

  • creates images with many more colors
  • makes color transparency possible
  • allows advanced image processes
Format
mla apa chicago
Your Citation
Bradley, Angela. "Imagecreatetruecolor() PHP Function." ThoughtCo, Aug. 21, 2017, thoughtco.com/imagecreatetruecolor-php-function-2694064. Bradley, Angela. (2017, August 21). Imagecreatetruecolor() PHP Function. Retrieved from https://www.thoughtco.com/imagecreatetruecolor-php-function-2694064 Bradley, Angela. "Imagecreatetruecolor() PHP Function." ThoughtCo. https://www.thoughtco.com/imagecreatetruecolor-php-function-2694064 (accessed May 21, 2018).