 |
| ::: 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 |
|
 |
 |
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.
|
| |

|
 |
| ::: Resources ::: |
|
|
| ::: New Templates ::: |
|
| ::: Other Tutorials ::: |
|
 |