PHP imagecreate() function

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

Save the following code as viewPicture.htm:


<html>/*ww w. ja va2  s.  c o m*/
 <body>
     <img src="picture1.php" />
 </body>
</html>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions