T4VN is an online PHP Help community that provides PHP Tutorials, PHP Examples, PHP Scripts, PHP Support
    HOME  |  HOSTING COUPON  |  TEMPLATE  |  PHP SCRIPTS  |  LINK TO US  |  LINK  |  REGISTER | CONTACT
::: Member Login :::
 Username
 Password
 
Forgot your password ?
::: PHP Tutotal :::
  PHP Basic (7)
  PHP Advanced (4)
  PHP Database (2)
  Coding Step By Step (8)
  PHP and AJAX (0)
::: PHP Example :::
  Arrays (1)
  Code Highlighters (3)
  Database Functions (12)
  Date & Time (5)
  E-Mail (6)
  Forms (5)
  Guestbooks (1)
  Logging (2)
  Miscellaneous (10)
  Password Generators (3)
  Randomizers (3)
  String Manipulation (10)
  User Authentication (6)
::: Search On T4VN :::
::: T4VN Statistics :::
  PHP Scripts : 61
  PHP Example : 67
  PHP Tutorials : 21
  PHP News : 93
  Total Coupon : 36
  Other Tutorials :
  Member : 209
  Visitor Online : 1
  Today Visit: 303
  Total Visitor : 262313
  Most Online : 31
::: Sponsored Links :::

PR 4 For This Webpage
Home Today :

GD Abstraction Layer v0.1

Author : Cody Brocious

This abstraction layer for GD will allow you to simplify the process of using GD.

PHP Example :

<?php
    define
('IMAGE_TRUECOLOR''1');
    class 
GD
    
{
        var 
$image;
        function 
GD()
        {
            if(!
function_exists('imagecreate'))
                die(
'You must have GD installed/loaded into PHP for the GD abstraction class to work.');
        }
        function 
Create($width$height$color null)
        {
            if(
$color === null)
                
$this->image imagecreate($width$height);
            else
                
$this->image imagecreatetruecolor($width$height);
        }
        function 
Load_From_JPEG($filename)
        {
            
$this->image imagecreatefromjpeg($filename);
        }
        function 
Load_From_GIF($filename)
        {
            if(!
function_exists('imagecreatefromgif'))
                die(
'Your version of GD does not have support for the GIF image format.');
            
$this->image imagecreatefromgif($filename);
        }
        function 
Load_From_PNG($filename)
        {
            
$this->image imagecreatefrompng($filename);
        }
        function 
Load_From_GD($filename)
        {
            
$this->image imagecreatefromgd($filename);
        }
        function 
Load_From_GD2($filename)
        {
            
$this->image imagecreatefromgd2($filename);
        }
        function 
Load_From_XPM($filename)
        {
            
$this->image imagecreatefromxpm($filename);
        }
        function 
Allocate_Color($r$g$b)
        {
            
imagecolorallocate($this->image$r$g$b);
        }
        function 
Color_At($x$y)
        {
            
$rgb ImageColorAt($this->image$x$y);
            
$r = ($rgb >> 16) & 0xFF;
            
$g = ($rgb >> 8) & 0xFF;
            
$b $rgb 0xFF;
            return array(
$r$g$b);
        }
        function 
Output_GD()
        {
            
ob_start();
            
imagegd($this->image);
            
$im ob_get_contents();
            
ob_end_clean();
            return 
$im;
        }
        function 
Output_GD2()
        {
            
ob_start();
            
imagegd2($this->image);
            
$im ob_get_contents();
            
ob_end_clean();
            return 
$im;
        }
        function 
Output_JPEG()
        {
            
ob_start();
            
imagejpeg($this->image);
            
$im ob_get_contents();
            
ob_end_clean();
            return 
$im;
        }
        function 
Output_GIF()
        {
            if(!
function_exists('imagegif'))
                die(
'Your version of GD does not have support the GIF image format.');
            
ob_start();
            
imagegif($this->image);
            
$im ob_get_contents();
            
ob_end_clean();
            return 
$im;
        }
        function 
Output_PNG()
        {
            
ob_start();
            
imagepng($this->image);
            
$im ob_get_contents();
            
ob_end_clean();
            return 
$im;
        }
    }
?>



An example usage of this class:


PHP Example :

<?php
$gd 
= new GD();
$gd->Load_From_PNG('yourimg.png');
print 
$gd->Output_JPEG();
?>



The example would load the PNG file 'yourimg.png' and output the JPEG version of it.

Other Example
Yahoo! Messenger(tm) Encryption algorithm


::: Resources :::
  Links Directory
  Programming 2 3
  Webmaster 2 3
  Web Design 2 3
  Web Hosting 2 3
  Other Links 2 3
  Asian ShowBiz News
  Teach Seo For You
::: New Templates :::




::: Other Tutorials :::
 Program Design

  Powered By T4VN.NET - Version 2.0 - CopyRight © T4VN.NET 2005-2007