NEWS CATEGORIES:



NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
Home / News / Webmaster / Tips and Tricks

Tips and Tricks


Images Manipulation With PHP

An Introduction to GD Library

By Catalin Bocanu, Web News Editor

7th of January 2008, 15:47 GMT

Adjust text size:


GD Library LOGO
Enlarge picture
Images can be processed using specialized softwares which are available for any operating system. On the Internet, images can be manipulated dynamically with the help of server side
programming languages.

PHP (Hypertext Preprocessor) allows you to create, process and output images in web browsers. In order to be able to manage images using PHP code, the PHP version must be compiled with GD graphics library. If you want to find out details about your version of GD library or if GD support exists, call phpinfo() function or GD_VERSION (only available as of PHP 5.2.4) from within a simple PHP script.

The GD library is coded in C programming language and provides "wrappers" for PHP and many other languages. The
image functions present in this library helps you to dynamically generate images (PNG, JPEG), thumbnails, apply filters to
images and more.

Let's consider for example the next script in order to demonstrate the execution of image processing actions with the help of PHP code and GD library:

CODE

The PHP header function determines the correct HTTP header type and, as a consequence, the web browser will render the script output as an image file. The imagedestroy() function is used to destroy the image loaded in the server memory in order to free the occupied memory.

The imagecreatefrompng () function will open the test.png image and the new image resource obtained will be contained in the variable $img. The imagefilter function is used to apply different filters to the image. In the example considered IMG_FILTER_GRAYSCALE and IMG_FILTER_BRIGHTNESS filters were used.

The first filter converts the image to grayscale and the second one changes the brightness to a specified level value (10 in this case). You can adjust the parameter value to see the image changes in browser output. Based on this script, you can also try to discover other functions available for image processing in PHP that you can include in your own scripts.

TAGS:

GD Library | Image Processing | Image Filters | Image Tools | PHP Tutorial


Rating:
Fair (2.3/5) 8 vote(s) so far    

Read by 903 user(s) | Add comment | Link to this article
Subscribe to news | Print article | Send to friend

© Copyright 2001-2008 Softpedia
Contact:

 

 

SEARCH THE NEWS ARCHIVE :




Today's News
| Yesterday's News | News Archive


MORE RELATED ARTICLES:


Tips for Using PHP in Safe Mode

Free Visual Tool for PHP.ini Configuration on Windows

What Should You Choose, PHP or ASP ?

A Free Multilingual Real Estate Website

Web Based Proxies

Tips to Improve Joomla Performance

Forms To Go

The Most Used Forum Application in the World

Content Management System Selection

Free Image Galleries

User opinions:


Comment #1 by: Eitan on 07 Jan 2008, 17:24 GMT reply to this comment

yea, only problem is GD crashes your RAM in massive traffic websites such as web2.0.

if you have such a website, the solution for you will be Imagick library for PHP. this library works on the hard drive in contrary for GD that works on RAM.

Share your opinion:

Your Name:
Your Email Address:
(will not be used for commercial purposes)
Solve this to prove you're not a bot: =
Your review/opinion:

 






SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   ENTER NEWS SITE   |   ENGLISH BOARD   |   ROMANIAN FORUM