Thursday, March 12, 2020

Imagecreatetruecolor() PHP Function

Imagecreatetruecolor() PHP Function 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 dont 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 colorsmakes color transparency possibleallows advanced image processes