Zapni si podporu GD2


PHP je můj koníček
Kód:
<?php
class ImageException extends Exception &#123;
	
	public function __construct &#40;&#41;
	&#123;
		print "Nedovolený formát souboru!";
	&#125;
&#125;

class Image &#123;

	protected $ImageName;
	protected $Properties = array &#40;&#41;;
	protected $Directory;
	public 	  $Type;
	
	public function __construct &#40; $name, $dir &#41;&#123; $this -> ImageName = $name; $this -> Directory = $dir; &#125;
	
	public function getProperties &#40;&#41;
	&#123;			
		 $this -> Properties = getimagesize &#40; $this -> Directory . $this -> ImageName &#41;;

		 switch &#40; $this -> Properties&#91;2&#93; &#41;
		 &#123;
		 	case 1&#58; $this -> Type = "gif"; 	break;
		 	case 2&#58; $this -> Type = "jpeg";	break;
			case 3&#58; $this -> Type = "png";	break;
 		 &#125;
		 
		 return new Image_Statement &#40;  $this -> Properties, $this -> Directory, $this -> ImageName &#41;;	
	&#125;		
&#125;

class Image_Statement &#123;

	protected $Properties = array &#40;&#41;;
	private $Height;
	private $Width;
	public $Type;
	private $Directory;
	private $ImageName;
	private $tmp;
		
	public function __construct &#40; $Properties, $Directory, $ImageName &#41;
	&#123;
		$this -> Properties = $Properties;
		$this -> Directory  = $Directory;
		$this -> ImageName  = $ImageName;
		$this -> tmp = $ImageName;
		
		$this -> Type = $this -> Properties&#91;2&#93;;
		
		if &#40; !is_array &#40; $this -> Properties &#41; || !is_string &#40; $this -> Directory &#41; || !is_string &#40; $this -> tmp &#41; 
			|| $this -> Properties&#91;2&#93; == 0 || $tis -> Properties > 3 || $this -> Properties&#91;2&#93; == "" &#41;
			throw new ImageException;
	&#125;
	
	public function resampledImage &#40; $width, $height &#41;
	&#123;
		$skelet = imagecreatetruecolor &#40; $width, $height &#41;;
		//vytvoreni obrazku ze vstupniho
		switch &#40; $this -> Type &#41;
		&#123;
			case 1&#58;	$res = imagecreatefromgif &#40; $this -> Directory . $this -> tmp &#41;; 	break;
			case 2&#58;	$res = imagecreatefromjpeg &#40; $this -> Directory . $this -> tmp &#41;; 	break;
			case 3&#58;	$res = imagecreatefrompng &#40; $this -> Directory . $this -> tmp &#41;; 	break;
		&#125;				
		//zmena velikosti
		imagecopyresampled &#40; $skelet, $res, 0, 0, 0, 0, $width, $height, $this -> Properties&#91;0&#93;, $this -> Properties&#91;1&#93; &#41;;
					 
		imagedestroy &#40; $res &#41;;
  
		switch &#40; $this -> Type &#41;&#123;
			
		   case 1&#58; 	imagegif &#40; $skelet, $this -> Directory . $this -> tmp &#41;; 	break;
		   case 2&#58; 	
		   			imagesetpixel &#40;$skelet, $width, $height, 20&#41;;
		   			imagejpeg &#40; $skelet, $this -> Directory . $this -> tmp &#41;; 	
		   break;
		   case 3&#58; 	imagepng &#40; $skelet, $this -> Directory . $this -> tmp &#41;; 	break;		   		   		   			  
		&#125;
		return $this;
	&#125;

	public function renameImage &#40; $name &#41;
	&#123;
		return &#40; rename &#40; $this -> Directory . $this -> tmp, $this -> Directory . $name &#41; &#41;;
	&#125;
	
	public function copyImage &#40; $name &#41;
	&#123;
		//vytvoreni nazvu obrazku
		copy &#40; $this -> Directory . $this -> ImageName, $this -> Directory . $name &#41;;
		//vlozeni do tmp pro moznost nastaveni velikosti v resampledImage
		$this -> tmp = addslashes &#40; $name &#41;;
		
		return $this;		
	&#125;	
	
	public function unlinkTmpImage &#40;&#41;
	&#123;
		if &#40; is_string &#40; $this -> ImageName &#41; &#41;
		&#123;			
			return &#40; unlink &#40; $this -> Directory . $this -> ImageName &#41; &#41;;
		&#125;
	&#125;
&#125;
?>
Edit:
Použítí je následující
Kód:
//upload na server //delej nejakou podminku na is_uploaded_file
move_uploaded_file&#40;$_FILES&#91;'newImage'&#93;&#91;'tmp_name'&#93;,$_SERVER&#91;'DOCUMENT_ROOT'&#93;."/path/".$tmp &#41;; 

//nová instance nastavi jmeno a cestu
$imh = new Image&#40; $tmp, $_SERVER&#91;'DOCUMENT_ROOT'&#93;."/path" &#41;; 

//zjisti udaje o obrazku preda objekt Image_Statement a tam zkontroluje
$proper = $imh -> getProperties &#40;&#41;;

//nstaveni jmen obrazku a prilozeni typu &#40;gif, jpeg, png&#41;
$nameB = $tmp."B.".$imh -> Type;
$nameS = $tmp."S.".$imh -> Type; 

//udela obrazek o veliksoti 320x220 a mensi 114x87
$big = $proper -> copyImage &#40; $nameB &#41; -> resampledImage &#40; 320, 220&#41;; 
$small = $proper -> copyImage &#40; $nameS &#41; -> resampledImage &#40; 114, 87&#41;; 

//zrusi tmp nahravanej obrazek kvuli velikosti
$destroyTmp = $proper -> unlinkTmpImage &#40;&#41;;
Trida je udelana jako mala FAKTORY predavam objekt z class Image do Image_Statement

huh
Edit2:
ve windowsech staci povolit jen tu knihovnu gd2.dll v php.ini a reset apache
v linuxu je myslim podpora gifu a png, ale jpeg musis mit zvlast zkompilovanej
tot asi vsechno