PHP imagecreate() function
In this chapter you will learn:
- What is PHP imagecreate() function
- Syntax for PHP imagecreate() function
- Parameter for PHP imagecreate() function
- Return value for PHP imagecreate() function
- Example - PHP imagecreate() function
- Example - PHP image script as img src
Description
imagecreate() returns an image identifier representing a blank image of specified size.
Syntax
PHP imagecreate() function has the following syntax.
resource imagecreate ( int $width , int $height )
Parameter
PHP imagecreate() function has the following parameters.
- width - The image width.
- height - The image height.
Return
Returns an image resource identifier on success, FALSE on errors.
Example 1
<?php// j ava2 s .c om
header("Content-Type: image/png");
$im = @imagecreate(110, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>
Example 2
The most basic image script looks like this:
Save the following code as picture.php
<?PHP// j a v a 2 s . co m
$image = imagecreate(400,300);
// do stuff to the image
imagejpeg($image, '', 75);
imagedestroy($image);
?>
Save the following code as viewPicture.htm:
<html>//from jav a2s. c om
<body>
<img src="picture1.php" />
</body>
</html>
Next chapter...
What you will learn in the next chapter:
- What is PHP imagecreatetruecolor () function
- Syntax for PHP imagecreatetruecolor () function
- Parameter for PHP imagecreatetruecolor () function
- Return value for PHP imagecreatetruecolor () function
- Example - PHP imagecreatetruecolor () function
Home » PHP Tutorial » PHP Image Functions