Saving and Building on Existing Images

Up to this point every image has been created in memory and immediately sent to the browser. You also have the option with PHP and GD to build on existing images and to save them to the server. The three relevant functions are

$image = imagecreatefromgif ($file_name); 

$image = imagecreatefrompng ($file_name);

$image = imagecreatefromjpg ($file_name);

Each of these functions would be used in lieu of the imagecreate() function. Note that which function you use should be based on the format of the source image, not the final one. You could theoretically build on a GIF or JPEG to create a PNG, although the quality of the image itself will suffer. Which function you can use is also dependent on the version ...

Get PHP Advanced for the World Wide Web: Visual QuickPro Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.