Kategori arşivi: Php

Php Curl ile Proxy örneği

<?php
	function chs(){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, "http://www.mehmetmutlu.com.tr/ip.php");
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_POST,true);
		curl_setopt($ch, CURLOPT_TIMEOUT, 10);

		//http://hidemyass.com/proxy-list/
		curl_setopt($ch, CURLOPT_PROXYPORT, '8080');
		curl_setopt($ch, CURLOPT_USERAGENT, "bots");
		curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
		curl_setopt($ch, CURLOPT_PROXY,'12.174.27.73');
		curl_setopt($ch, CURLOPT_PROXYUSERPWD,'');
		
		$output = curl_exec($ch);
		curl_close($ch);
		return $output;
	}
	print_r(chs());

?>

xdebug nedir? xdebug kurulumu nasıl yapılır?

Merhabalar, Performanslı php sayfaları yapmak istediğimizde nerede hata yaptığızı hangi metotların sistemden daha fazla kaynak tükettiğini görmek için xdebug bileşenini

inceliyeceğiz,

öncelikle php sistemimize xdebug kurulumunu yapmamız gerekiyor,

http://www.xdebug.org/find-binary.php


adresinden php info sayfamızı kopyalıp yapıştırarak bizim hangi sürüme ihtiyacımızın oldugunu çıkartalım,

Kurulum için yapmamız gereken işlemleri bize söylüyor,
Bize söylediklerine artı olarak php.ini içerisine,

aşağıdaki kodları da ekliyoruz,

xdebug.profiler_enable = 1
xdebug.profiler_output_dir=d:/wamp/xdebug
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_mode=req

debug loglarının tutulacağı dizini kendinize göre ayarlıyabilirsiniz,

sunucumuzu restart ettikden sonra, php dosyamızı çalıştıralım,(php normalden ağır çalışabilir)

ardından logları tutacağımız dizine, cachegrind.out isimli dosya gelecek, bu dosya php işlemleri ile ilgili, sunucumuzun durumunu barındığı log dosyası, bu log dosyasını ise,

http://sourceforge.net/projects/wincachegrind/ adresindeki program ile rahatlıkla okuyabiliriz,

Php ile Rakamlı Parayı Yazıyla Paraya Çevirme

Merhabalar arkadaşlar, php ile rakamla yazılmış parayı yazıyla yazılmış haline çevirmeye ihtiyacım oldu aşadaki fonksiyon ile 9 basamaklı paraya kadar çevirme yapabilirsiniz.

<?php
    function money($money='0.00') {
        $money = explode('.',$money);
        if(count($money)!=2) return false;
        $money_left = $money['0'];
        $money_right = $money['1'];

        //DOKUZLAR
        if(strlen($money_left)==9){
            $i = (int) floor($money_left/100000000);
            if($i==1) $l9="YÜZ";
            if($i==2) $l9="İKİ YÜZ";
            if($i==3) $l9="ÜÇ YÜZ";
            if($i==4) $l9="DÖRT YÜZ";
            if($i==5) $l9="BEŞ YÜZ";
            if($i==6) $l9="ALTI YÜZ";
            if($i==7) $l9="YEDİ YÜZ";
            if($i==8) $l9="SEKİZ YÜZ";
            if($i==9) $l9="DOKUZ YÜZ";
            if($i==0) $l9="";
            $money_left = substr($money_left,1,strlen($money_left)-1);
        }

        //SEKİZLER
        if(strlen($money_left)==8){
            $i = (int) floor($money_left/10000000);
            if($i==1) $l8="ON";
            if($i==2) $l8="YİRMİ";
            if($i==3) $l8="OTUZ";
            if($i==4) $l8="KIRK";
            if($i==5) $l8="ELLİ";
            if($i==6) $l8="ATMIŞ";
            if($i==7) $l8="YETMİŞ";
            if($i==8) $l8="SEKSEN";
            if($i==9) $l8="DOKSAN";
            if($i==0) $l8="";
            $money_left=substr($money_left,1,strlen($money_left)-1);
        }

        //YEDİLER
        if(strlen($money_left)==7){
            $i = (int) floor($money_left/1000000);
            if($i==1){
                if($i!="NULL"){
                    $l7 = "BİR MİLYON";
                }else{
                    $l7 = "MİLYON";
                }
            }
            if($i==2) $l7="İKİ MİLYON";
            if($i==3) $l7="ÜÇ MİLYON";
            if($i==4) $l7="DÖRT MİLYON";
            if($i==5) $l7="BEŞ MİLYON";
            if($i==6) $l7="ALTI MİLYON";
            if($i==7) $l7="YEDİ MİLYON";
            if($i==8) $l7="SEKİZ MİLYON";
            if($i==9) $l7="DOKUZ MİLYON";
            if($i==0){
                if($i!="NULL"){
                    $l7="MİLYON";
                }else{
                    $l7="";
                }
            }
            $money_left=substr($money_left,1,strlen($money_left)-1);
        }

        //ALTILAR
        if(strlen($money_left)==6){
            $i = (int) floor($money_left/100000);
            if($i==1) $l6="YÜZ";
            if($i==2) $l6="İKİ YÜZ";
            if($i==3) $l6="ÜÇ YÜZ";
            if($i==4) $l6="DÖRT YÜZ";
            if($i==5) $l6="BEŞ YÜZ";
            if($i==6) $l6="ALTI YÜZ";
            if($i==7) $l6="YEDİ YÜZ";
            if($i==8) $l6="SEKİZ YÜZ";
            if($i==9) $l6="DOKUZ YÜZ";
            if($i==0) $l6="";
            $money_left = substr($money_left,1,strlen($money_left)-1);
        }

        //BEŞLER
        if(strlen($money_left)==5){
            $i = (int) floor($money_left/10000);
            if($i==1) $l5="ON BİN";
            if($i==2) $l5="YİRMİ BİN";
            if($i==3) $l5="OTUZ BİN";
            if($i==4) $l5="KIRK BİN";
            if($i==5) $l5="ELLİ BİN";
            if($i==6) $l5="ATMIŞ BİN";
            if($i==7) $l5="YETMİŞ BİN";
            if($i==8) $l5="SEKSEN BİN";
            if($i==9) $l5="DOKSAN BİN";
            if($i==0) $l5="";
            $money_left=substr($money_left,1,strlen($money_left)-1);
        }

        //DÖRTLER
        if(strlen($money_left)==4){
            $i = (int) floor($money_left/1000);
            if($i==1){
                if($i!=""){
                    $l4 = "BİR BİN";
                }else{
                    $l4 = "BİN";
                }
            }
            if($i==2) $l4="İKİ BİN";
            if($i==3) $l4="ÜÇ BİN";
            if($i==4) $l4="DÖRT BİN";
            if($i==5) $l4="BEŞ BİN";
            if($i==6) $l4="ALTI BİN";
            if($i==7) $l4="YEDİ BİN";
            if($i==8) $l4="SEKZ BİN";
            if($i==9) $l4="DOKUZ BİN";
            if($i==0){
                if($i!=""){
                    $l4="BİN";
                }else{
                    $l4="";
                }
            }
            $money_left=substr($money_left,1,strlen($money_left)-1);
        }

        //ÜÇLER
        if(strlen($money_left)==3){
            $i = (int) floor($money_left/100);
            if($i==1) $l3="YÜZ";
            if($i==2) $l3="İKİYÜZ";
            if($i==3) $l3="ÜÇYÜZ";
            if($i==4) $l3="DÖRTYÜZ";
            if($i==5) $l3="BEŞYÜZ";
            if($i==6) $l3="ALTIYÜZ";
            if($i==7) $l3="YEDİYÜZ";
            if($i==8) $l3="SEKİZYÜZ";
            if($i==9) $l3="DOKUZYÜZ";
            if($i==0) $l3="";
            $money_left=substr($money_left,1,strlen($money_left)-1);
        }

        //İKİLER
        if(strlen($money_left)==2){
            $i = (int) floor($money_left/10);
            if($i==1) $l2="ON";
            if($i==2) $l2="YİRMİ";
            if($i==3) $l2="OTUZ";
            if($i==4) $l2="KIRK";
            if($i==5) $l2="ELLİ";
            if($i==6) $l2="ATMIŞ";
            if($i==7) $l2="YETMİŞ";
            if($i==8) $l2="SEKSEN";
            if($i==9) $l2="DOKSAN";
            if($i==0) $l2="";
            $money_left=substr($money_left,1,strlen($money_left)-1);
        }

        //BİRLER
        if(strlen($money_left)==1){
            $i = (int) floor($money_left/1);
            if($i==1) $l1="BİR";
            if($i==2) $l1="İKİ";
            if($i==3) $l1="ÜÇ";
            if($i==4) $l1="DÖRT";
            if($i==5) $l1="BEŞ";
            if($i==6) $l1="ALTI";
            if($i==7) $l1="YEDİ";
            if($i==8) $l1="SEKİZ";
            if($i==9) $l1="DOKUZ";
            if($i==0) $l1="";
            $money_left=substr($money_left,1,strlen($money_left)-1);
        }

        //SAĞ İKİ
        if(strlen($money_right)==2){
            $i = (int) floor($money_right/10);
            if($i==1) $r2="ON";
            if($i==2) $r2="YİRMİ";
            if($i==3) $r2="OTUZ";
            if($i==4) $r2="KIRK";
            if($i==5) $r2="ELLİ";
            if($i==6) $r2="ALTMIŞ";
            if($i==7) $r2="YETMİŞ";
            if($i==8) $r2="SEKSEN";
            if($i==9) $r2="DOKSAN";
            if($i==0) $r2="SIFIR";
            $money_right=substr($money_right,1,strlen($money_right)-1);
        }

        //SAĞ BİR
        if(strlen($money_right)==1){
            $i = (int) floor($money_right/1);
            if($i==1) $r1="BİR";
            if($i==2) $r1="İKİ";
            if($i==3) $r1="ÜÇ";
            if($i==4) $r1="DÖRT";
            if($i==5) $r1="BEŞ";
            if($i==6) $r1="ALTI";
            if($i==7) $r1="YEDİ";
            if($i==8) $r1="SEKİZ";
            if($i==9) $r1="DOKUZ";
            if($i==0) $r1="";
            $money_right=substr($money_right,1,strlen($money_right)-1);
        }

        return "$l9 $l8 $l7 $l6 $l5 $l4 $l3 $l2 $l1 TÜRK LİRASI $r2 $r1 KURUŞ";
    }

	echo money('654214254.62');
?>

Aşağıdaki gibi çıktı verecektir

ALTI YÜZ ELLİ DÖRT MİLYON İKİ YÜZ ON DÖRT BİN İKİYÜZ ELLİ DÖRT TÜRK LİRASI ALTMIŞ İKİ KURUŞ

Php Gd2 Class

Php gd2 ile resize(yeniden boyutlandırma), Thumbnail(küçük resim),crop (resim kesme),Rotate (resim çevirme)efects (resim efektleri) gibi işlemleri hızlandırmak için geliştirilmiş bir class

class.gd2.php

<?php

/* Errors */
define('GD2_ERROR_NOTICE', 0);
define('GD2_ERROR_ERROR', 1);

class Gd2{

var $useGdFilters;

var $imgInfos = array(
    'type' => '',
    'width' => 0,
    'height' => 0
);

var $bgColor = array(
    'red' => 255,
    'green' => 255,
    'blue' => 255
);

var $_gdIsLoaded;
var $_imgHandler;
var $_supportedTypes = array();
var $_errors = array(
    'notices' => array(),
    'errors' => array()
);

/*
* PHP 4 Constructor
*/
function Gd2($img = '', $red = 255, $green = 255, $blue = 255){
    $this->__construct($img, $red, $green, $blue);
    register_shutdown_function(array(&$this,'__destruct'));
}

/*
* PHP 5 Constructor
*/
function __construct($img = '', $red = 255, $green = 255, $blue = 255){

    if(!$this->_gdIsLoaded = extension_loaded('gd'))
        return $this->_setError('GD library is not installed in your system');
    elseif(!function_exists('imagecreatetruecolor'))
        return $this->_setError('This class require the version 2 of GD library');

    $types = imageTypes();

    if ($types & IMG_PNG){
        $this->_supportedTypes['png']['read'] = true;
        $this->_supportedTypes['png']['write'] = true;
    }

    if ($types & IMG_GIF || function_exists('imagegif')){
        $this->_supportedTypes['gif']['read'] = true;
        $this->_supportedTypes['gif']['write'] = true;
    }
    elseif (function_exists('imagecreatefromgif')){
        $this->_supportedTypes['gif']['read'] = true;
        $this->_supportedTypes['gif']['write'] = false;
    }

    if ($types & IMG_JPG){
        $this->_supportedTypes['jpeg']['read'] = true;
        $this->_supportedTypes['jpeg']['write'] = true;
    }

    $this->bgColor['red'] = min(255,max(0,$red));
    $this->bgColor['green'] = min(255,max(0,$green));
    $this->bgColor['blue'] = min(255,max(0,$blue));

    $this->useGdFilters = function_exists('imagefilter');

    if(is_file($img))
        $this->createFromFile($img);
}

/*
* Destructor
*/
function __destruct(){
    $this->destroy();
}

/************************************ Publics Methods ************************************/

/*
* Image resource destroyer
*
* @return bool
* @access public
*/
function destroy(){
    if(is_resource($this->_imgHandler)){
        imagedestroy($this->_imgHandler);
        return true;
    }
    return false;
}

/*
* Image resource destroyer
*
* @param string $file the file path
*
* @return bool
* @access public
*/
function createFromFile($file){
    if(!$this->_gdIsLoaded)
        return false;
    elseif(!is_file($file))
        return $this->_setError('Hata! Gorsel Bulunamadi.');

    $this->_init();

    $ext = $this->getExt($file);

    if(!$this->_isSupported($ext,'read'))
        return $this->_setError('Image "'.$ext.'" are not supported');

    if ($ext === 'jpeg')
        $this->_imgHandler = @imagecreatefromjpeg($file);
    elseif($ext === 'png')
        $this->_imgHandler = @imagecreatefrompng($file);
    elseif($ext === 'gif')
        $this->_imgHandler = @imagecreatefromgif($file);

    if(!$this->_imgHandler)
        return $this->_setError('Fail to create the image resource');

    $this->imgInfos['type'] = $ext;
    $this->imgInfos['width'] = imagesx($this->_imgHandler);
    $this->imgInfos['height'] = imagesy($this->_imgHandler);

    return true;
}

/*
* Resize the image to the specified dimensions
*
* @param int $new_width the image width
* @param int $new_height the image height
* @param int $x vertical offset for crop resizing
* @param int $y horizontal offset for crop resizing
* @param int $size image dimensions for crop resizing
*
* @return bool
* @access public
*/
function CreateLogo($pic_file, $logo_file){
    $this->img_pic = imagecreatefromjpeg($pic_file);
    $this->img_logo = imagecreatefrompng($logo_file);
}
function setAlign($align) {
    if ($align =="TL") {
        $this->dpy = 5;
        $this->dpx = 5;
    } elseif ($align =="TR") {
        $this->dpy = 5;
        $this->dpx = imagesx($this->img_pic)-(imagesx($this->img_logo)+5);
    } elseif ($align =="BR") {
        $this->dpy = imagesy($this->img_pic)-(imagesy($this->img_logo)+5);
        $this->dpx = imagesx($this->img_pic)-(imagesx($this->img_logo)+5);
    } elseif ($align =="BL") {
        $this->dpy = imagesy($this->img_pic)-(imagesy($this->img_logo)+5);
        $this->dpx = 5;
    } elseif ($align =="BC") {
        $this->dpy = imagesy($this->img_pic)-(imagesy($this->img_logo)+5);
        $dc = imagesx($this->img_pic)/2;
        $dc2 = imagesx($this->img_logo)/2;
        $this->dpx = $dc-$dc2;
    } elseif ($align =="TC") {
        $this->dpy = 5;
        $dc = imagesx($this->img_pic)/2;
        $dc2 = imagesx($this->img_logo)/2;
        $this->dpx = $dc-$dc2;
    } else {
        $this->dpy = 5;
        $this->dpx = 5;
    }

}
function AddLogo($align){

    $this->setAlign($align);
    $sx = imagesx($this->img_logo);
    $sy = imagesy($this->img_logo);

    imagecopy($this->img_pic, $this->img_logo, $this->dpx, $this->dpy, 0, 0, $sx, $sy);
}
function resizeImage( $new_width, $new_height, $x = 0, $y = 0,$size = 0){
    if($this->_isReady()){
        $image_p = imagecreatetruecolor($new_width, $new_height);
        imagecopyresampled($image_p, $this->_imgHandler, 0, 0,0,0, $new_width, $new_height, $this->imgInfos['width'], $this->imgInfos['height']);
        imagedestroy($this->_imgHandler);
        $this->_imgHandler = $image_p;

            if(!empty($size)){
                $image2 = imagecreatetruecolor($size,$size);
                imagecopyresampled($image2,$this->_imgHandler,$x,$y,0,0,$size,$size,$size,$size);
                imagedestroy($this->_imgHandler);
                $this->_imgHandler = $image2;
            }

        return true;
    }
    else return false;
}

/*
* Resize the image to the specified dimensions
*
* @param int $new_width the image width
* @param int $new_height the image height
* @param int $x vertical offset for crop resizing
* @param int $y horizontal offset for crop resizing
* @param int $size image dimensions for crop resizing
*
* @return bool
* @access public
*/
function oneSizeThumbnail($size){
    if($this->_isReady()){
        if($this->imgInfos['width'] > $this->imgInfos['height']){
            $size_percent = (int)($size / ($this->imgInfos['width'] / 100));
            $new_height = (int) ($size_percent * ($this->imgInfos['height']/100));
            $new_width = $size;
            $y = ((int)$size - (int)$new_height) /2 ;
            $x = 0;
        }else{
            $size_percent = (int)($size / ($this->imgInfos['height'] / 100));
            $new_width = (int) ($size_percent * ($this->imgInfos['width']/100));
            $new_height = $size;
            $x = ($size - $new_width) / 2;
            $y = 0;
        }
        return $this->resizeImage($new_width,$new_height,$x,$y,$size);
    }
    else return false;
}

/*
* Resize the image to the specified dimensions
*
* @param int $new_width the image width
* @param int $new_height the image height
* @param int $x vertical offset for crop resizing
* @param int $y horizontal offset for crop resizing
* @param int $size image dimensions for crop resizing
*
* @return bool
* @access public
*/
function maxSizeThumbnail($size){
    if($this->_isReady()){
        if($this->imgInfos['width'] > $this->imgInfos['height']){
            $size_percent = (int)($size / ($this->imgInfos['width'] / 100));
            $new_height = (int) ($size_percent * ($this->imgInfos['height']/100));
            $new_width = $size;
            $y = ($size - $new_height) / 2;
            $x = 0;
        }else{
            $size_percent = (int)($size / ($this->imgInfos['height'] / 100));
            $new_width = (int) ($size_percent * ($this->imgInfos['width']/100));
            $new_height = $size;
            $x = ($size - $new_width) / 2;
            $y = 0;
        }

        return $this->resizeImage($new_width,$new_height,$x,$y);
    }
    else return false;
}

/*
* Crop the image to the specified dimensions
*
* @param int $width the croped image width
* @param int $height the croped image height
* @param int $x vertical offset for croping
* @param int $y horizontal offset for croping
*
* @return bool
* @access public
*/
function cropImage($width,$height,$x,$y){
    if($this->_isReady()){
        $image2 = imagecreatetruecolor($width, $height);
        imagecopymerge($image2,$this->_imgHandler,0,0,$x,$y,$width, $height,100);
        imagedestroy($this->_imgHandler);
        $this->_imgHandler = $image2;

        return true;
    }else return false;
}

/*
* Apply rotation to the image
*
* @param int $anle the rotation angle
* @param int $color the background color for some rotation
*
* @return bool
* @access public
*/
function imageRotate($angle,$color = 0){
    if($this->_isReady()){
        if(!is_numeric($angle))
            return $this->_setError('Invalid "angle" parameter');
        elseif(empty($angle) || $angle === 360)
            return true;

    if(empty($color))
        $color = imagecolorat($this->_imgHandler,0,0);
    elseif(!is_array($color))
        $color = $this->_hex2rgb($color);

    $this->_imgHandler = imagerotate($this->_imgHandler, $angle, imageColorAllocate($this->_imgHandler,$color['red'],$color['green'],$color['blue']));
    }else return false;
}

/*
* Reverse the image
*
* @return bool
* @access public
*/
function mirror(){
    if($this->_isReady()){
    $tmpimage = imagecreatetruecolor($this->imgInfos['width'], $this->imgInfos['height']);

    for ($x=0;$x<$this->imgInfos['width'];++$x)
        imagecopy($tmpimage,$this->_imgHandler, $x, 0, $this->imgInfos['width'] - $x - 1, 0, 1, $this->imgInfos['height']);

    imagedestroy($this->_imgHandler);
    $this->_imgHandler = $tmpimage;

    return true;
    }
return false;
}

/*
* Apply Negate filter to the image
*
* @return bool
* @access public
*/
function effectNegate(){
    if($this->useGdFilters){
        if($this->_isReady())
            return imagefilter($this->_imgHandler, IMG_FILTER_NEGATE);
        else
        return false;
    }else return $this->_setError('Image filters is not available on PHP4');
}

/*
* Apply Colorize filter to the image
*
* @param string | array $color the color of the filter
*
* @return bool
* @access public
*/
function effectColorize($color){
    if($this->useGdFilters){
        if($this->_isReady()){
            if(!is_array($color))
                $color = $this->_hex2rgb($color);

            return imagefilter($this->_imgHandler,IMG_FILTER_COLORIZE,$color['red'],$color['green'],$color['blue']);
        }else return false;
    }else return $this->_setError('Image filters is not available on PHP4');
}

/*
* Apply Grayscale filter to the image
*
* @return bool
* @access public
*/
function effectGrayscale(){
    if($this->useGdFilters){
        if($this->_isReady())
            return imagefilter($this->_imgHandler, IMG_FILTER_GRAYSCALE);
        else
            return false;
    }else return $this->_setError('Image filters is not available on PHP4');
}

/*
* Apply Edge Detect filter to the image
*
* @return bool
* @access public
*/
function effectEdgeDetect(){
    if($this->useGdFilters){
        if($this->_isReady())
            return imagefilter($this->_imgHandler, IMG_FILTER_EDGEDETECT);
        else
            return false;
    }else return $this->_setError('Image filters is not available on PHP4');
}

/*
* Apply Selective Blur filter to the image
*
* @return bool
* @access public
*/
function effectSelectiveBlur(){
    if($this->useGdFilters){
        if($this->_isReady())
            return imagefilter($this->_imgHandler, IMG_FILTER_SELECTIVE_BLUR);
        else
            return false;
    }
    else return $this->_setError('Image filters is not available on PHP4');
}

/*
* Apply Contrast filter to the image
*
* @param int $val the effect level
*
* @return bool
* @access public
*/
function effectContrast($val){

    if($this->useGdFilters){
        if($this->_isReady()){
            return imagefilter($this->_imgHandler, IMG_FILTER_CONTRAST,$val);
        }
        else return false;
    }
    else return $this->_setError('Image filters is not available on PHP4');
}

/*
* Apply Brightness filter to the image
*
* @param int $val the effect level
*
* @return bool
* @access public
*/
function effectBrightness($val){
    if($this->useGdFilters){
        if($this->_isReady())
            return imagefilter($this->_imgHandler, IMG_FILTER_BRIGHTNESS,$val);
        else
            return false;
    }
    else return $this->_setError('Image filters is not available on PHP4');
}

/*
* Apply Gausian Blur filter to the image
*
* @return bool
* @access public
*/
function effectGaussianBlur(){
    if($this->useGdFilters){
        if($this->_isReady())
            return imagefilter($this->_imgHandler, IMG_FILTER_GAUSSIAN_BLUR);
        else
            return false;
    }
    else return $this->_setError('Image filters is not available on PHP4');
}

/*
* Apply Smooth filter to the image
*
* @param int $val the effect level
*
* @return bool
* @access public
*/
function effectSmooth($val){
    if($this->useGdFilters){
        if($this->_isReady())
            return imagefilter($this->_imgHandler,IMG_FILTER_SMOOTH,$val);
        else
            return false;
    }
    else return $this->_setError('Image filters is not available on PHP4');
}

/*
* Apply Emboss filter to the image
*
* @return bool
* @access public
*/
function effectEmboss(){
    if($this->useGdFilters){
        if($this->_isReady())
            return imagefilter($this->_imgHandler,IMG_FILTER_EMBOSS);
        else
            return false;
    }
    else return $this->_setError('Image filters is not available on PHP4');
}

/*
* Apply Mean Removal filter to the image
*
* @return bool
* @access public
*/
function effectMeanRemoval(){
    if($this->useGdFilters){
        if($this->_isReady())
            return imagefilter($this->_imgHandler,IMG_FILTER_MEAN_REMOVAL);
        else
            return false;
    }
    else return $this->_setError('Image filters is not available on PHP4');
}

/*
* Apply negate filter to the image
*
* @return bool
* @access public
*/
function setTransparent($color){
    if($this->_isReady()){
        if(!is_array($color))
            $color = $this->_hex2rgb($color);

        if(!imageistruecolor($this->_imgHandler))
            $this->toTrueColor();

        imagecolortransparent($this->_imgHandler,imagecolorallocate($this->_imgHandler,$color['red'],$color['green'],$color['blue']));

    }
    else return false;
}

/*
* Convert an image with palette color to true color image
*
* @return bool
* @access public
*/
function toTrueColor(){
    if($this->_isReady()){
        if(!imageistruecolor($this->_imgHandler)){
            $img2 = imagecreatetruecolor($this->imgInfos['width'], $this->imgInfos['height']);

            imagecopymerge($img2,$this->_imgHandler,0,0,0,0,$this->imgInfos['width'],$this->imgInfos['height'],$this->imgInfos['width'],$this->imgInfos['height'],100);

            imagedestroy($this->_imgHandler);
            $this->_imgHandler = $img2;
        }
        return true;
    }
    return false;
}

/*
* set the background color for the created images
*
* @param string|array $color the color in hex or rgb (all "rgb" or "r" or "g" or "b") format
*
* @return bool
* @access public
*/
function setBgColor($color){
    if(is_string($color)){
        $this->bgColor = $this->_hex2rgb($color);
        return true;
    }elseif(is_array($color)){
        if($this->_isRgbColor($color)){
            $this->bgColor = $color;
            return true;
        }elseif(isset($color['red'])){
            $this->bgColor['red'] = $color['red'];
            return true;
        }elseif(isset($color['green'])){
            $this->bgColor['green'] = $color['green'];
            return true;
        }elseif(isset($color['blue'])){
            $this->bgColor['blue'] = $color['blue'];
            return true;
        }
        else return false;
    }
    else return false;
}

/*
* display the image
*
* @param string $type the output type
*
* @return bool
* @access public
*/
function display($type = ''){
    if($this->_isReady()){
        if($type === '') // i don't use empty because i don't remember if anyone of the IMAGETYPE_* constante have 0 for value
            $type = $this->imgInfos['type'];
        elseif(is_numeric($type))
            $type = $this->type2Ext($type);
        else{
            $type = strtolower($type);
            if($type === 'jpg')
                $type = 'jpeg';
        }

        if(!$this->_isSupported($type,'write'))
            return $this->_setError('Image "'.$type.'" not supported for output');

        header('Content-type: image/'.$type);

        if ($type === 'jpeg')
            imagejpeg($this->_imgHandler);
        elseif($type === 'png')
            imagepng($this->_imgHandler);
        elseif($type === 'gif')
            imagegif($this->_imgHandler);

    }elseif($this->isError())
        $this->_getErrorImage();
    else
    $this->_getErrorImage('No image handler found');
}

/*
* save the image
*
* @param string $filePath the save path
* @param int $quality output quality for jpeg
*
* @return bool
* @access public
*/
function save( $filePath, $quality = 100){
    if($this->_isReady()){
        if(empty($filePath))
            return $this->_setError('Can not save image file in a empty file path');

        $type = $this->getExt($filePath);

        if(!$this->_isSupported($type,'write'))
            return $this->_setError('Image "'.$type.'" not supported for output');

        if ($type === 'jpeg'){
            if(!is_numeric($quality))
                $quality = 100;
            else
                $quality = min(100,max(0,$quality));

            imagejpeg($this->_imgHandler,$filePath,$quality);
        }elseif ($type === 'png')
            imagepng($this->_imgHandler,$filePath);
        elseif ($type === 'gif')
            imagegif($this->_imgHandler, $filePath);
    }
}

/*
* convert an imagetype to the image extension string
*
* @param string $type the type of file you want get
*
* @return str on success or bool on fail
* @access public
*/
function type2Ext($type){
    if($type === IMAGETYPE_GIF)
        return 'gif';
    elseif($type === IMAGETYPE_PNG)
        return 'png';
    elseif($type === IMAGETYPE_JPEG)
        return 'jpeg';
    else
        return false;
}

/*
* Public isSupported method
*
* @param string $type the type of file you want check
* @param string|array $mode the mode you want check
*
* @return bool
* @access public
*/
function isSupported($type, $mode = 'read') {
    return $this->_isSupported(strtolower($type),(is_array($mode) ? $mode : strtolower($mode)));
}

/*
* return the file extension
*
* @param string $fileName the file name or path
*
* @return str
* @access public
*/
function getExt($fileName){
    if(empty($fileName))
        return '';
    elseif(false === ($pos = strrpos($fileName,'.')))
        return '';

    $ext = strtolower(substr($fileName,++$pos));

    if($ext === 'jpg')
        $ext = 'jpeg';

    return $ext;
}

/*
* Check if the class have an error
*
* @return bool
* @access public
*/
function isError() {
    return !empty($this->_errors['errors']);
}

/*
* Return the consigned errors
*
* @param bool $toStr returned the value on array or on string
* @param bool $html if return string the separator must be a normal line return with space or a html line break
*
*
* @return array | string
* @access public
*/
function getErrors( $toStr = false, $html = false){
    if(empty($this->_errors['errors']))
        return '';

    if(!$toStr)
        return $this->_errors['errors'];
    elseif(count($this->_errors['errors']) === 1)
        return $this->_errors['errors'][0];
    else{
        $ret = '';

        foreach($this->_errors['errors'] as $error)
            $ret .= $error.($html ? '<br />' : " \n");

        return $ret;
    }
}

/*
* Return the last consigned error
*
* @return str
* @access public
*/
function getLastError(){
    if(empty($this->_errors['errors']))
        return false;

    return $this->_errors['errors'][(count($this->_errors)-1)];
}

/************************************ Privates Methodss ************************************/

/*
* Initialise the class attributs
*
* @return void
* @access private
*/
function _init(){
    $this->destroy();
    $this->imgInfos = array();
}

/*
* Check if the class can work
*
* @return bool
* @access private
*/
function _isReady() {
    return ($this->_gdIsLoaded && !$this->isError() && is_resource($this->_imgHandler));
}

/*
* Check if an extension is supported for reading and/or writting
*
* @param string $type the type of file you want check
* @param string|array $mode the mode you want check
*
* @return bool
* @access private
*/
function _isSupported($type, $mode){
    if(!isset($this->_supportedTypes[$type]))
        return false;
    elseif(is_array($mode))
        return ($this->_supportedTypes[$type]['read'] && $this->_supportedTypes[$type]['write']);
    elseif(!isset($this->_supportedTypes[$type][$mode]))
        return false;
    else
        return $this->_supportedTypes[$type][$mode];
}

/*
* error handling
*
* @param string $msg the error message
* @param string|array $level the level of the error
*
* @return bool
* @access private
*/
function _setError( $msg, $level = GD2_ERROR_ERROR){
    $msg = trim($msg);

    if($level === GD2_ERROR_NOTICE){
        $this->_errors['notices'][] = $msg;

        return true;
    }else{
        $this->_errors['errors'][] = $msg;

        return false;
    }
}

/*
* create an image with the given error or with the consigned errors
*
* @param string $test the error message
*
* @return void
* @access private
*/
function _getErrorImage($text = ''){
    if(!$this->_gdIsLoaded){
        $this->_gdIsNotLoaded();
        return false;
    }elseif(empty($text))
        $text = $this->getErrors(true);

    $errors = explode("\n",$text);
    $nbe = count($errors);

    $width = ($this->imgInfos['width'] < 300) ? 300 : $this->imgInfos['width'];
    $height = (30*$nbe)+60;
    $finalheight = ($this->imgInfos['height'] < $height) ? $height : $this->imgInfos['height'];

    $eImg = imagecreate($width,$finalheight);
    $bg = imagecolorallocate($eImg, 255, 255, 255);
    $textcolor = imagecolorallocate($eImg, 255, 0, 0);

    for($i=0,$j=30;$i<$nbe;$i++,$j+=10)
        imagestring($eImg, 2, 30, $j, trim($errors[$i]), $textcolor);

    if($this->_isSupported('jpeg','write')){
        header("Content-type: image/jpeg");
        imagejpeg($eImg);
    }elseif($this->_isSupported('gif','write')){
        header("Content-type: image/gif");
        imagegif($eImg);
    }elseif($this->_isSupported('png','write')){
        header("Content-type: image/png");
        imagepng($eImg);
    }
}

function _gdIsNotLoaded(){
    header("Content-type: image/jpeg");
    echo base64_decode('/9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4'.
    'wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBkZWZhdWx0IHF1YWxpdHkK/9sAQwAIBgYHBgUIBwcHCQkIC'.
    'gwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQk'.
    'MCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyM'.
    'jIy/8AAEQgAZAEsAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALU'.
    'QAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXG'.
    'BkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5S'.
    'VlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29'.
    '/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwA'.
    'BAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDR'.
    'EVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrK'.
    'ztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A9'.
    '/ooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACii'.
    'igAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAC'.
    'iiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigArL1+WSLSx5UjRmW5t4WZDtbY8'.
    'yIwBHIJViMjkdQQa1KZLFHPC8M0ayRSKVdHGVYHggg9RSkrpo0pSUJxk+jRyUMcV74iTSvP1aO3tVu'.
    'g0b30isWH2YqQ6PuZcSkjeSRuI4wAN/QLqa98OaXd3D7557SKSRsAbmZAScDjqaJNA0aa3ht5NIsHg'.
    'g3eVG1shWPccnaMYGTycVo1EINO7OnEYiFSCjG+nf5/nfX03e5jaX5/2nX4Yp23Je4hM7NKsZaCJsY'.
    'LZ27mJ2ggc4GKyLfUb+4bwuLe5gglvtKkci4d3UtiBuFLbpGA3dWyAWOTgg9KmladH9q8uwtV+15+0'.
    '7YVHnZznfx83U9fU0w6LpRtFtDplmbZVKrCYF2AFgxAXGMFlB+oB7UnCVv67lRxNJSu1fbov5Wr+eu'.
    'tv8zJ0PWtV13ddRQ2cNmjQ5iYsZGEkEUhG7oCvmHBwd3TCY3HOfxfqAu/KgggmW5WKeyaVREGheeKN'.
    'SdsjthhLkMVTBU/KeQOySKONpGSNVaRtzlRgscAZPqcAD6AVXXStOR2dbC1DtIZSwhUEuWVi3TqWRD'.
    'n1UHsKThO2jHDE4dTblT000/wCDvv1+XpnSard6XeW0WrSWvkSRy/6RDG6+ZIDHsRUJJ3kNJhAWLbM'.
    'juovaLeSajoWn30yqstzbRzOEGFBZQTjPbmn31k975ai+uraMZEiQFV80HHBYqWXvypU89c4xYiijg'.
    'hSGGNY4o1CoiDCqBwAAOgq0mpeRhUnTlSVl73X8fLz6aadDDS/vYo9dIMD3EF6sUG5iqndHEVGGfG7'.
    '5wAoKBm/u7iavaNd3F3ZubsxfaI5DHIEQoVOAcMhLbSM9mYEYYHDCpk0rTo/tXl2Fqv2vP2nbCo87O'.
    'c7+Pm6nr6mpbW1t7K3S3tLeKCBM7Y4kCKuTk4A46kmiMZJjq1aUoNJa6a/JJ/j08zDm1nUYtRvDstf'.
    'sNrfwWe3DeZJ5ohGc5wu0y56HcOMLjcczUNc1Wfw1PMJoIWvtHm1C3aKNla3CqhKFt/zNiUYcbcFc7'.
    'TnA682tu2/dbxHfIsr5QfM642sfUjauD22j0ptvp9lZzTzW1pBBLcNumeKMK0h5OWIHJ5PX1NS4SfU'.
    '2p4qjCz5NVb52X+ev4bBZvIYTHPcwT3MTbZmgTYoP3gNpZip2lTye+e9U5Z508U2lvuU28llO4Ubgw'.
    'ZXiHPzbSCHHVcjBwfmIq9a2tvZW6W9pbxQQJnbHEgRVycnAHHUk019PspL6O+e0ga8jXalw0YMijng'.
    'NjIHJ/M1bTsjmjOCnJvZp9F1X4fL0OatPEOryadZTTx2Hn6hYC6gRCVCNmJdpLMA5YzAhcpgjbuOd4'.
    'Jr7Wbp9HWO8tbe4+3yQzqbd+v2eRwrxiTjGDxuYN8jhsYB6U6fZGFYTaQGJYTAqGMbRGcAoBj7p2jj'.
    'pwPSmf2Vp39nf2f8AYLX7D/z7eSvl9d33cY68/Ws/Zy6s6vrVFO8YWevRbO669lbTq9W76mHf+J3g1'.
    'S1+xmK40+SeC1dwq4Mku0ja5kBPyOj4WNgRn5hyVvaXGZbnX7aSadovtu1czvuQNBExCtnKjLMRgjG'.
    'eMVoyafZTXIuZbSB7gKqiVowWwGDAZxnAYBh7jNMTStOj+1eXYWq/a8/adsKjzs5zv4+bqevqarlle'.
    '7M3Xo+z5Yqztb8U7/n95zUGsasmheHILGFrq8u9OW4lldVlbCrGDkNLHkkyA53Z46HOQX+t6lKse8Q'.
    'WIXUbK0ltzKfN8xzDI4VwcMMOUK45AZt2Plron0XSpLGOxfTLNrONtyW7QKY1PPIXGAeT+ZqaTT7Ka'.
    '5FzLaQPcBVUStGC2AwYDOM4DAMPcZqfZzta5ssXQUubk6t+e911ttptoSyiQwuIXVJSp2M67lB7EgE'.
    'ZHtkfWubstU1O6s/D8Fn9lje90w3Mss4kl8sqIeg3ZfPmEctnvk4w3SSxRzwvDNGskUilXRxlWB4II'.
    'PUVFbafZWaxLa2kECxKyxiKMKEDEFgMDgEgE+pAq5RbehyUasIRfMrv/gNfm0/kM0q+/tPSLK/8vy/'.
    'tUEc2zdnbuUHGe+M1zQ8XzyR6dDGsBvJ7ZftS7G229w0sEW089VMzFo87uFBK5yetiijghSGGNY4o1'.
    'CoiDCqBwAAOgqjBo8S+a15PLqMkkZiL3aocRnqgVVVcHvxk4GSQBhSU2kkzSjUoRlKU43V9F9/9bmd'.
    'aa7cJrMun372oS1jnae5VTGp2LbuGwWO0BZyDkn7ucjpUXh7WdZ1uJbkpYJAnkeYuHDP5kEUjYOSF2'.
    'mQkfe3cD5cbjuLpWnJbwW6WFqsFvIJYYxCoWNwSQyjGAcknI9TUtva29ohS2t4oUOMrGgUcKFHT0VV'.
    'H0AHakoSvq9CpV6HI1GGr6/PV26X/AA6EWp3E1rp0stuIjPwsYlYAFiQAOSASSeFyuTgZXORjW/iKe'.
    'CaBdTaBIysySssTI4mXyykWzLYch3wql94UMpIOK6GWKOeF4Zo1kikUq6OMqwPBBB6iqMmjxC3htbO'.
    'eXT7SPcDBZKkauCckZ25XvyhU8k5zghyUr3RFCdFR5ai+fy76/LS3cxtO8QaleDTbiQWaWs8Nv5pAJ'.
    'XzZEVihffmNvnyqshDfKN4LgCG01fUtP0G5luLmC9vHvZYbaFYyr5+1mEnDSfMoLphcqAMKW53V0q6'.
    'VpyXEFwlharPbxiKGQQqGjQAgKpxkDBIwPU086fZM1yxtIC10oW4JjGZgBgB+PmGCRz2qVCXc2eKoX'.
    'soaXT2XRvT8d9+mxy83iDXraSzgurSC3lmZlJljBLgyQRI4VJWCgNOSRuJYR9V3cdLpV9/aekWV/wC'.
    'X5f2qCObZuzt3KDjPfGafbafZWaxLa2kECxKyxiKMKEDEFgMDgEgE+pAqWKKOCFIYY1jijUKiIMKoH'.
    'AAA6CqjGSerMa9alUglGFnfdad+mvl18tijpv2j7fq/n+b5f2tfI35xs8iLO3Pbdu6d8980aB9o/wC'.
    'Ec0v7Z5v2r7JF53nZ379g3bs85znOavJFHG0jJGqtI25yowWOAMn1OAB9AKIoo4IUhhjWOKNQqIgwq'.
    'gcAADoKpRszKdVSi1bt+CsPoooqjEKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAK'.
    'KKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAoooo'.
    'AKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAoo'.
    'ooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigA'.
    'ooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiii'.
    'gAooooAKKKKACiiigAooooAKKKKACiiigAooooA//2Q==');
}

/*
* Check if the given color is an rgb color array
*
* @param array $color the color to test
*
* @return bool
* @access private
*/
function _isRgbColor($color){
    if(!isset($color['red'],$color['green'],$color['blue']))
        return false;

    return ($color['red'] < 255 && $color['red'] > 0 &&
    $color['green'] < 255 && $color['green'] > 0 &&
    $color['blue'] < 255 && $color['blue'] > 0);
}

/*
* convert an hex color to an rgb color array
*
* @param array $color the color to convert
*
* @return array
* @access private
*/
function _hex2rgb($hex){
    $hex = strtr($hex,'#','');

    if(strlen($hex) === 3)
        return array('red' => hexdec($color{0}.$color{0}),'green' => hexdec($color{1}.$color{1}),'blue' => hexdec($color{2}.$color{2}));
    else
        return array('red' => hexdec(substr($hex,0,2)),'green' => hexdec(substr($hex,2,2)),'blue' => hexdec(substr($hex,4,2)));
    }
}
?>

example.php

<?php

require('class.gd2.php');

$gd = new Gd2("DSC_0096.jpg");

if(isset($_GET['op']))
{
if($gd->useGdFilters)
{
switch((int)$_GET['op'])
{
case 1: $gd->resizeImage(150,150); break;
case 2: $gd->maxSizeThumbnail(150); break;
case 3: $gd->oneSizeThumbnail(150); break;
case 4: $gd->cropImage(200,200,50,50); break;
case 5: $gd->imageRotate(90); break;
case 6: $gd->mirror(); break;
case 7: $gd->effectBrightness(50); break;
case 8: $gd->effectSmooth(2); break;
case 9: $gd->effectEmboss(); break;
case 10: $gd->effectGaussianBlur(); break;
case 11: $gd->effectMeanRemoval(); break;
case 12: $gd->effectNegate(); break;
case 13: $gd->effectGrayscale(); break;
case 14: $gd->effectEdgeDetect(); break;
case 15: $gd->effectSelectiveBlur(); break;
case 16: $gd->effectContrast(-30); break;
case 17: $gd->effectColorize('#00ff00'); break;
case 18: $gd->createFromFile('DSC.jpg'); break;
}
}
else
{
switch((int)$_GET['op'])
{
case 1: $gd->resizeImage(150,150); break;
case 2: $gd->maxSizeThumbnail(150); break;
case 3: $gd->oneSizeThumbnail(150); break;
case 4: $gd->cropImage(200,200,50,50); break;
case 5: $gd->imageRotate(90); break;
case 6: $gd->mirror(); break;
case 7: $gd->createFromFile('DSC.jpg'); break;
}
}

$gd->display('png');
}
else
{
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>-[Gd2 Class Demo]-</title>
<style type="text/css">
body { background-color:#e2e2e2; }
th { background-color:#c0c0c0;text-align:center; }
img { margin-left:auto;margin-right:auto;border:none; }
table { margin-left:auto;margin-right:auto;text-align:center; }
.main { width:90%;border:1px solid #000000;padding:0px; }
.sub { width:100%;border:none; }
.cObj { width:90%;border:1px solid #000000;margin-left:auto;margin-right:auto;text-align:left; }
pre { margin-left:30%; }
.cObj th, .main th { font-size:28px; }
.sub th { font-size:16px;padding:5px; }
.sub td { padding:10px; }
</style>
</head>
<body>
<?php
$tests = array(
'',
'$gd->resizeImage(150,150);',
'$gd->maxSizeThumbnail(150);',
'$gd->oneSizeThumbnail(150);',
'$gd->cropImage(200,200,50,50);',
'$gd->imageRotate(90);',
'$gd->mirror();'
);

if($gd->useGdFilters)
{
$tests[] = '$gd->effectBrightness(50);';
$tests[] = '$gd->effectSmooth(30);';
$tests[] = '$gd->effectEmboss();';
$tests[] = '$gd->effectGaussianBlur();';
$tests[] = '$gd->effectMeanRemoval();';
$tests[] = '$gd->effectNegate();';
$tests[] = '$gd->effectGrayscale();';
$tests[] = '$gd->effectEdgeDetect();';
$tests[] = '$gd->effectSelectiveBlur();';
$tests[] = '$gd->effectContrast(-30);';
$tests[] = '$gd->effectColorize(\'#00ff00\');';
}

$tests[] = 'Error simulation';

$nb = count($tests);

echo '<table class="main">
<tr>
<th>Gd2 class demo samples</th>
</tr>
<tr>
<td>
<br />
<img src="DSC_0096.jpg" width="'.$gd->imgInfos['width'].'" height="'.$gd->imgInfos['height'].'" />
<br />
( Original Image )
</td>
</tr>
<tr>
<td>
<table class="sub">';

for($i=1;$i<$nb;$i+=2)
{
echo'<tr>
<th>'.$tests[$i].'</th><th>'.(isset($tests[$i+1]) ? $tests[$i+1] : '').'</th>
</tr>
<tr>
<td><img src="?op='.$i.'" /></td><td>'.(isset($tests[$i+1]) ? '<img src="?op='.($i+1).'" />' : '').'</td>
</tr>';
}

echo '</table>
</td>
</tr>
</table>
<table class="cObj">
<tr>
<th>Gd2 Class Object</th>
</tr>
<tr>
<td>
<br />
<pre>'.print_r($gd,true).'</pre>
</td>
</tr>
</table>
<br />
</body>
</html>';

$gd->destroy();
}
?>

Php Upload Class

%100 tüm testlerimi yapmadım ama bayram tatilinde boş durmayıp upload fonksiyon kütüphanemi bitireyim dedim,

Kullanım Örneği;

<?php

include('upload.class.php');

$a = new upload;

/*Zorunlu değil boş bırakırsak root dizine atar*/
$a->directory = 'D:\wamp\www'.DIRECTORY_SEPARATOR;

/*Girmek zorunlu değil girmek gerede 250K,2M,1G vb, parametreler ile girilmelidir*/
$a->allowed_size = '2G';

/*Girmek zorunlu değil Dosya uzantısı kontrolü yapar girmek gerekirse array('uzantı') şeklinde */
$a->allowed_ext = array('jpg','gif','png');

/*Girmek zorunlu değil Dosya uzantısına aldırmaksınızın eğer resimli işlemler yapıyor isek resim oldugunu belirmekte fayda var*/
$a->check_image_type = true;

/*Girmek zorunlu değil Dosyaya yeni ad vermek iser isek not uzantıyı yazmıor sadece adı değiştiriyor*/
$a->file_rename = uniqid();

/*girmek zorunlu hangi file formdan geldiğini belirmemiz gerekiyor. multi upload fonksiyonunu kapattım*/
$file = $a->save('ahmet');

/*hata çıktıları*/
if($file){
	print_r($file);
}else{
	print_r($a->error);
}

?>

upload.class.php

<?php
	/*
		@author mehmetmutlu.com.tr
		@16 Kasım 2010, Salı
	*/

class upload{
	public $directory = NULL;
	public $allowed_size = NULL;
	public $allowed_ext = NULL;
	public $check_image_type = false;
	public $file_rename = NULL;
	public $error = NULL;
	public $renadme = NULL;

	public function save($file=NULL){
		if(!$this->check_directory()){
			die('Upload dizini yok yada yazma izini geçersiz.');
		}
		if($file==NULL){
			die('class save(\'\') file değeri geçersiz');
		}else{
			if($_FILES[$file]['error']==0 && $_FILES[$file]['size']!=0){
				if(!$this->check_allowed_ext($_FILES[$file])){
					$this->error[] = array(1,'Geçersiz dosya uzantısı.');
				}elseif(!$this->check_allowed_size($_FILES[$file])){
					$this->error[] = array(2,'Upload limit aşımı. Maksimum upload boyutu '.$this->allowed_size);
				}elseif(!$this->check_image($_FILES[$file])){
					$this->error[] = array(3,'Geçersiz resim dosyası');
				}else{
					if(move_uploaded_file($_FILES[$file]['tmp_name'], $this->directory . $this->path($_FILES[$file]))){
						return array('file'=>$this->path($_FILES[$file]),'ext'=>pathinfo(basename($_FILES[$file]['name']),PATHINFO_EXTENSION),'size'=>$_FILES[$file]['size']);
					}else{
						$this->error[] = array(0,'Upload sırasında hata oluştu');
						return false;
					}
				}
			}else{
				$this->error[] = array(0,'Upload sırasında hata oluştu');
				return false;
			}
		}
	}

	private function path($file){
		if($this->file_rename==NULL){
			return  basename($file['name']);
		}else{
			return $this->file_rename.'.'.pathinfo(basename($file['name']),PATHINFO_EXTENSION);
		}
	}

    private function check_directory(){
		if(is_dir(realpath($this->directory)) || is_writable(realpath($this->directory))){
            return true;
        }
		return false;
    }

    private function check_allowed_size($file){
		if($this->allowed_size!=NULL){
			if(!preg_match('#[0-9]++[GMKB]#',$this->allowed_size)){
				return false;
			}
			switch(substr($this->allowed_size,-1)){
				case 'G': $size = intval($this->allowed_size) * pow(1024,3); break;
				case 'M': $size = intval($this->allowed_size) * pow(1024,2); break;
				case 'K': $size = intval($this->allowed_size) * pow(1024,1); break;
				default : $size = intval($this->allowed_size);               break;
			}
			return ($file['size'] <= $size);
		}else{
			return true;
		}
    }

    private function check_allowed_ext($file){
		if($this->allowed_ext!=NULL){
			if (in_array(pathinfo($file['name'],PATHINFO_EXTENSION),$this->allowed_ext)){
				return true;
			}else{
				return false;
			}
		}else{
			return true;
		}
    }

	private function check_image($file){
		if($this->check_image_type==false){
			return true;
		}else{
			if(!getimagesize($file['tmp_name'])) {
				return false;
			}else{
				return true;
			}
		}
	}

}

?>

not: class içerisinde bazı fonsiyonları Yusuf Koç‘un upload classın dan alıntı yapılmıştır…