imagecreatetruecolor( ) is a built-in function in PHP that creates a new true color image. It returns a blank image of a given size.
resource imagecreatetruecolor($width, $height)
imagecreatetruecolor() takes two parameters, $width and $< /span>Height.
$Width - The $< /span>width parameter is used to set the image width.
$height - The $< /span>height parameter is used to set the image height.
imagecreatetruecolor() Returns the resource identifier if the image is successful, and returns false if there is an error.
<?php // Set the vertices of polygon $values = array( 150, 50, // Point 1 (x, y) 50, 250, // Point 2 (x, y) 250, 250 // Point 3 (x, y) ); // Create the size of image or blank image $image = imagecreatetruecolor(700, 350); // Set the background color of image $background_color = imagecolorallocate($image, 122, 122, 122); // Fill background with above selected color imagefill($image, 0, 0, $background_color); // Allocate a color for the polygon $image_color = imagecolorallocate($image, 0, 255, 255); // Draw the polygon imagepolygon($image, $values, 3, $image_color); // Output the picture to the browser header('Content-type: image/png'); imagepng($image); ?>
<?php header ('Content-Type: image/gif'); $img = @imagecreatetruecolor(550, 220) or die('Cannot Initialize new GD image stream'); $text_color = imagecolorallocate($img, 255, 255, 0); imagestring($img, 10, 50, 50, 'A Simple PHP Example', $text_color); imagepng($img); imagedestroy($img); ?>
The above is the detailed content of How to create a new truecolor image in PHP using imagecreatetruecolor()?. For more information, please follow other related articles on the PHP Chinese website!