PHP Tutorial - PHP imagecreate() function






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/*  ww w  .j av  a2 s . c  o  m*/
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
$image = imagecreate(400,300);
// do stuff to the image
imagejpeg($image, '', 75);
imagedestroy($image);
?>

Save the following code as viewPicture.htm:

<html>
 <body>
     <img src="picture1.php" />
 </body>
</html>