class ve örneğin linki: http://uploaded.to/file/lx0khyr6
[img]img%20src=http://img68.resimup.net/dm/R9BR.jpg[/img]
class ın içeriği:
Kod: Tümünü seç
<?php
/*
* clipex
* clipex.php
* Image processing class v1.4 (PHP class)
* @author Ekrem R. YURTTAŞ
* Mail: e.r.yurttas@gmail.com
* Released under GNU General Public License
* http://www.gnu.org/licenses/gpl.html
* @copyright 2012
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
error_reporting(0);
class clipex {
//variables for class settings
var $ImgType; //current image type
var $ImgInfo; //after upload as temp getimagesize
var $ImgMime; //current image mime type
var $ImageNewName; //image name after resample / compress
var $ImgTempName; //server temp name
var $TEMPDir='clipex_temp/'; //temp directory
var $TempName; //temp image name
var $TempImage; //temp image name
var $MimeType=array("image/jpeg","image/pjpeg","image/png"); //supported mime types for files
public function RandName()
{
$leng = mt_rand(5,10); //random name lenght
$RName = '';
while (strlen($RName) < $leng)
{
$RName.=chr(rand(65,90)); //with chars (only uppercase chars 65-90; look ascii table.)
}
return $RName;
}
public function ControlMime($fileN) //control and set imagemimetype
{
$fileN=$fileN['type'];
if (in_array($fileN,$this->MimeType)){ $this->ImgMime=$fileN; return true; } else { return false; }
}
public function LoadImage($fileN)
{
$this->ImgTempName=$fileN['tmp_name'];
if ($this->ControlMime($fileN)){
return $this->LoadTempImg();
}
}
public function GETImageType()
{
$imgtype=getimagesize($this->ImgTempName);
return $imgtype[2];
}
public function LoadTempImg()
{
switch ($this->ImgMime){
case 'image/jpeg':{ //for jpg
$this->TempImage=imagecreatefromjpeg($this->ImgTempName);
$this->TempName=$this->TEMPDir.$this->RandName().'.jpg';
imagejpeg($this->TempImage,$this->TempName,100);
$this->ImgInfo=getimagesize($this->TempName);
if ($this->ImgInfo[2]==IMAGETYPE_JPEG){
return $this->TempName;
} else { return false; }
};break;
case 'image/pjpeg':{ //for jpg
$this->TempImage=imagecreatefromjpeg($this->ImgTempName);
$this->TempName=$this->TEMPDir.$this->RandName().'.jpg';
imagejpeg($this->TempImage,$this->TempName,100);
$this->ImgInfo=getimagesize($this->TempName);
if ($this->ImgInfo[2]==IMAGETYPE_JPEG){
return $this->TempName;
} else { return false; }
};break;
case 'image/png':{ //for png
$this->TempImage=imagecreatefrompng($this->ImgTempName);
$this->TempName=$this->TEMPDir.$this->RandName().'.png';
imagepng($this->TempImage,$this->TempName);
$this->ImgInfo=getimagesize($this->TempName);
if ($this->ImgInfo[2]==IMAGETYPE_PNG){
return $this->TempName;
} else { return false; }
};break;
}
}
private function getWidth()
{
return imagesx($this->TempImage);
}
private function getHeight()
{
return imagesy($this->TempImage);
}
public function ImageCompress($iWidth,$iHeight)
{
$Comp_Img=imagecreatetruecolor($iWidth,$iHeight);
imagecopyresampled($Comp_Img,$this->TempImage,0,0,0,0,$iWidth,$iHeight,$this->getWidth(),$this->getHeight());
$this->TempImage=$Comp_Img;
}
public function ImageResize($iWidth,$iHeight,$iCoordx,$iCoordy)
{
$Res_Img=imagecreatetruecolor($iWidth,$iHeight);
imagecopyresampled($Res_Img,$this->TempImage,0,0,$iCoordx,$iCoordy,$iWidth,$iHeight,$iWidth,$iHeight);
$this->TempImage=$Res_Img;
}
public function SaveImg($destDir,$destFileName,$Compress=100,$permiss=null,$autoDeleteTemp=true)
{
$opst=false;
switch ($this->GETImageType())
{
case IMAGETYPE_JPEG:{ $this->ImageNewName=$destFileName.'.jpg'; if (imagejpeg($this->TempImage,$destDir.$this->ImageNewName,$Compress)); $opst=true; };break;
case IMAGETYPE_PNG:{ $this->ImageNewName=$destFileName.'.png'; if (imagepng($this->TempImage,$destDir.$this->ImageNewName)); $opst=true; };break;
}
if ($autoDeleteTemp)
{
unlink($this->TempName);
}
return $opst;
}
public function MakeWaterMark()
{
//
}
public function DestroyObject()
{
//
}
public function GiveImagePath()
{
return $this->TempName;
}
public function GiveImageName()
{
return $this->ImageNewName;
}
}
?>