Image processing
in PHP
PHP is not limited to creating just HTML output. It can
also be used to create and manipulate image files in a variety of
different image formats, including gif, png, jpg, wbmp, and xpm.
Even more convenient, PHP can output image streams directly
to a browser. You will need to compile PHP with the GD library of
image functions for this to work. GD and PHP may also require other
libraries, depending on which image formats you want to work with.
You can use the image functions in PHP to get the size of JPEG,
GIF, PNG, SWF, TIFF and JPEG2000 images.
Image processing Requirement
PHP needs GD to process images. Since PHP 4.3 there is a bundled
version of the GD lib. This bundled version has some additional features
like alpha blending, and should be used in preference to the external
library since its codebase is better maintained and more stable.
For PHP 5, which with GD bundled, you will also be able to
create and manipulate images.
The format of images you are able to manipulate depend on the version
of GD you install, and any other
libraries GD might need to access
those image formats. Versions of GD older
than gd-1.6 support GIF format images, and do not support PNG, where
versions greater than gd-1.6 and less than gd-2.0.28 support PNG,
not GIF. GIF support was re-enabled in gd-2.0.28.
GD installation
If you use PHP version newer than 4.3, you don't need
to install GD since it is bundled. But this feature is turned off
by default. GD library requires libpng and libjpeg to compile.
For windows users, you need enable GD by changing php.ini.
you need include GD2 DLL. Open php.ini in your favorite editor,
find
;extension=php_gd2.dll then
remove the semicolon before it, it will be extension=php_gd2.dll.
Save your php.ini and reboot your web server
like the following (like we did in Install
phpMyAdmin,MySql, PHP )
- Open a DOS console window, type following command:
- Shut down IIS server -- (net stop iisadmin)
- Restart IIS -- (net start w3svc)
- Or reboot your PC.
Check GD bundle in PHP
After you reboot your webserver(or PC), you might want to check
if GD library has been enabled or not.
Saving the following code to a .php file.
Load this file in your browser like http://localhost/info.php or
http://www.yoursite.com/info.php. If your GD library is enabled,
you should be able to see the following information in the browser.
|