PHP
  Home arrow PHP arrow Page 3 - Filtering Image Streams with the GD Library in PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Filtering Image Streams with the GD Library in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2007-08-27


    Table of Contents:
  • Filtering Image Streams with the GD Library in PHP
  • Manipulating the colors of an image stream
  • Controlling brightness and contrast with the imagefilter() function
  • More graphic filters with the imagefilter() function

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Filtering Image Streams with the GD Library in PHP - Controlling brightness and contrast with the imagefilter() function
    ( Page 3 of 4 )

    In the section that you just read, I explained how to use the imagefilter() function to apply some basic graphic filters to an existing image stream. However, the versatility exposed by this function allows you to implement many other popular filters as well. 

    Below I coded another pair of practical examples. They show how to use this helpful function to control the brightness and contrast of a specified image stream. In these examples I used the same sample image that you saw in the previous section.

    Given that, here are the respective signatures for these code samples:

    // example of 'imagefilter()' function - Changes the brightness
    of the image

    try{
       if(!$image=imagecreatefromgif('clouds.gif')){
         throw new Exception('Error creating image');
       }
       // apply filter to image
       if(!imagefilter($image,IMG_FILTER_BRIGHTNESS,30)){
         throw new Exception('Error applying filter to image');
       }
       // display image to the browser
       header("Content-type: image/gif");
       imagegif($image);
       // free memory
       imagedestroy($image);

    }
    catch(Exception $e){
        echo $e->getMessage();
        exit();
    }

    // example of 'imagefilter()' function - Changes the contrast of
    the image

    try{
       if(!$image=imagecreatefromgif('clouds.gif')){
         throw new Exception('Error creating image');
       }
       // apply filter to image
       if(!imagefilter($image,IMG_FILTER_CONTRAST,30)){
         throw new Exception('Error applying filter to image');
       }
       // display image to the browser
       header("Content-type: image/gif");
       imagegif($image);
       // free memory
       imagedestroy($image);
       
    }
    catch(Exception $e){
        echo $e->getMessage();
        exit();
    }

    Definitely, after studying the signature for the above examples, you'll have to admit that the "imagefilter()" function that comes with the GD library is extremely useful for controlling some aspects of a selected image stream, such as its brightness and contrast. In this case you can see that the function accepts the type of filter to be applied, along with its intensity, as an input argument.

    So far, so good, right? I hope you see the great potential of the "imagefilter()" function. It will let you apply a bunch of popular graphic filters to a selected image stream, which can be a real time saver for those PHP applications that fetch multiple images from one or more database tables.

    Nevertheless, if you're actually thinking that the capacity of this function is only limited to applying the set of filters that you saw in the previous examples, I'm afraid that you're wrong, since it has many others that can be really handy.

    If you're interested in learning how to use the remaining filters that can be applied with the "imagefilter()" function, click the link below and read the next section. You won't be disappointed, trust me.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT