Using Existing Images

 

As you can see, creating images from scratch can be very tedious. It is often best to modify an existing image if you want anything but the simplest graphics. In addition to imageCreate() there are many imageCreateFrom... functions. The only thing differentiating most of them is the particular graphics file format they read.
int imageCreateFromPNG ( string filename )
int imageCreateFromJPEG ( string filename )
int imageCreateFromWBMP ( string filename )
int imageCreateFromGIF ( string filename )
int imageCreateFromGD ( string filename )
int imageCreateFromGD2 ( string filename )
int imageCreateFromXBM ( string filename )
int imageCreateFromXPM ( string filename )

Returns an image identifier representing the image obtained from the given filename or URL.


int imageCreateFromString ( string image )

Returns an image identifier representing the image obtained from the given string.


int imageCreateFromGD2Part ( string filename, int srcX, int srcY, int width, int height )

Create a new image from a given part of GD2 file or URL.

  
<?PHP
/*
tree.php
Cycles through the 3 abstract pngs with each refresh
*/

session_start(); // use sessions to remember state

switch ($_SESSION['png']) {
    case 
'tree1.png'// if 1, cycle to 2
        
$_SESSION['png'] = 'tree2.png' ;
        break;
    case 
'tree2.png'// if 2, cycle to 3
        
$_SESSION['png'] = 'tree3.png' ;
        break;
    default:          
// otherwise cycle to 1
        
$_SESSION['png'] = 'tree1.png' ;
        break;
}

// create, send headers, output & destroy
$im imageCreateFromPNG($_SESSION['png']) ;
header('Content-type: image/png');
imagePNG($im);
imageDestroy($im);
?>

(c) FreeFoto.com
Image Supplied by FreeFoto.com