Zapni si podporu GD2
PHP je můj koníček 
Kód:
<?php
class ImageException extends Exception {
public function __construct ()
{
print "Nedovolený formát souboru!";
}
}
class Image {
protected $ImageName;
protected $Properties = array ();
protected $Directory;
public $Type;
public function __construct ( $name, $dir ){ $this -> ImageName = $name; $this -> Directory = $dir; }
public function getProperties ()
{
$this -> Properties = getimagesize ( $this -> Directory . $this -> ImageName );
switch ( $this -> Properties[2] )
{
case 1: $this -> Type = "gif"; break;
case 2: $this -> Type = "jpeg"; break;
case 3: $this -> Type = "png"; break;
}
return new Image_Statement ( $this -> Properties, $this -> Directory, $this -> ImageName );
}
}
class Image_Statement {
protected $Properties = array ();
private $Height;
private $Width;
public $Type;
private $Directory;
private $ImageName;
private $tmp;
public function __construct ( $Properties, $Directory, $ImageName )
{
$this -> Properties = $Properties;
$this -> Directory = $Directory;
$this -> ImageName = $ImageName;
$this -> tmp = $ImageName;
$this -> Type = $this -> Properties[2];
if ( !is_array ( $this -> Properties ) || !is_string ( $this -> Directory ) || !is_string ( $this -> tmp )
|| $this -> Properties[2] == 0 || $tis -> Properties > 3 || $this -> Properties[2] == "" )
throw new ImageException;
}
public function resampledImage ( $width, $height )
{
$skelet = imagecreatetruecolor ( $width, $height );
//vytvoreni obrazku ze vstupniho
switch ( $this -> Type )
{
case 1: $res = imagecreatefromgif ( $this -> Directory . $this -> tmp ); break;
case 2: $res = imagecreatefromjpeg ( $this -> Directory . $this -> tmp ); break;
case 3: $res = imagecreatefrompng ( $this -> Directory . $this -> tmp ); break;
}
//zmena velikosti
imagecopyresampled ( $skelet, $res, 0, 0, 0, 0, $width, $height, $this -> Properties[0], $this -> Properties[1] );
imagedestroy ( $res );
switch ( $this -> Type ){
case 1: imagegif ( $skelet, $this -> Directory . $this -> tmp ); break;
case 2:
imagesetpixel ($skelet, $width, $height, 20);
imagejpeg ( $skelet, $this -> Directory . $this -> tmp );
break;
case 3: imagepng ( $skelet, $this -> Directory . $this -> tmp ); break;
}
return $this;
}
public function renameImage ( $name )
{
return ( rename ( $this -> Directory . $this -> tmp, $this -> Directory . $name ) );
}
public function copyImage ( $name )
{
//vytvoreni nazvu obrazku
copy ( $this -> Directory . $this -> ImageName, $this -> Directory . $name );
//vlozeni do tmp pro moznost nastaveni velikosti v resampledImage
$this -> tmp = addslashes ( $name );
return $this;
}
public function unlinkTmpImage ()
{
if ( is_string ( $this -> ImageName ) )
{
return ( unlink ( $this -> Directory . $this -> ImageName ) );
}
}
}
?>
Edit:
Použítí je následující
Kód:
//upload na server //delej nejakou podminku na is_uploaded_file
move_uploaded_file($_FILES['newImage']['tmp_name'],$_SERVER['DOCUMENT_ROOT']."/path/".$tmp );
//nová instance nastavi jmeno a cestu
$imh = new Image( $tmp, $_SERVER['DOCUMENT_ROOT']."/path" );
//zjisti udaje o obrazku preda objekt Image_Statement a tam zkontroluje
$proper = $imh -> getProperties ();
//nstaveni jmen obrazku a prilozeni typu (gif, jpeg, png)
$nameB = $tmp."B.".$imh -> Type;
$nameS = $tmp."S.".$imh -> Type;
//udela obrazek o veliksoti 320x220 a mensi 114x87
$big = $proper -> copyImage ( $nameB ) -> resampledImage ( 320, 220);
$small = $proper -> copyImage ( $nameS ) -> resampledImage ( 114, 87);
//zrusi tmp nahravanej obrazek kvuli velikosti
$destroyTmp = $proper -> unlinkTmpImage ();
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