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."


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
mla apa chicago
Your Citation
Bradley, Angela. "Imagecreatetruecolor() PHP Function." ThoughtCo, Jan. 29, 2020, Bradley, Angela. (2020, January 29). Imagecreatetruecolor() PHP Function. Retrieved from Bradley, Angela. "Imagecreatetruecolor() PHP Function." ThoughtCo. (accessed January 24, 2021).