ClipEX Class

Web tabanlı uygulama geliştirme araçları(PHP, ASP vb...) ile ilgili konuları buraya yazabilirsiniz.
Cevapla
Kullanıcı avatarı
CiTiZEN
Üye
Mesajlar: 1163
Kayıt: 06 Oca 2008 04:15

ClipEX Class

Mesaj gönderen CiTiZEN »

Marhabalar arkadaşlar, resim kırpmak, upload etmek vs. gibi işlemler için kullanılabilecek OPEN SOURCE geliştirdiğim clipEX eklentisinin PHP kısmıdır. GPL lisansı ile dağıtıyorum, yakında görsel katmanını da jquery ile eklenti olarak tasarlayıp bu class a watermark gibi bir kaç özellik daha ekleyip yayınlayacağım.Örnekte basit kullanımı var, localhost unuzdan çalıştırabilirsiniz.Umarım faydalı olur.Konu çok boş kalmasın diye geliştirmekte olduğum jquery görsel katmanının fotografını da ekledim.normal kullanımı bu şekilde.

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;
	}
}
?>
UWESIS CORPORATION
Cevapla