<?php
class Image {
var $Name;
var $Size;
var $FType;
var $Width;
var $Height;
var $ResizedWidth=600;
var $ResizedHeight=450;
var $TmpName;
var $PicDir="./";
var $Strech=true;
function Image($nPicDir,$nPicArr) {
$this->PicDir=$nPicDir;
$this->Name=$nPicArr["name"];
$this->Size=$nPicArr["size"];
$this->FType=$nPicArr["type"];
$this->TmpName=$nPicArr["tmp_name"];
if ($this->FType!="image/gif" && $this->FType!="image/pjpeg" && $this->FType!="image/jpeg")
$this->FType=null;
}
function GetInfo() {
$out=' Name: '.$this->Name.'<br>
FileSize: '.$this->Size.' byte<br>
FileType: '.$this->FType.'<br>';
return $out;
}
function Resample($NewName) {
if ($this->FType=="image/gif")
$OldImg=imagecreatefromgif($this->TmpName);
else if ($this->FType=="image/pjpeg" || $this->FType=="image/jpeg")
$OldImg=imagecreatefromjpeg($this->TmpName);
if ($OldImg) {
$this->Width=imagesx($OldImg);
$this->Height=imagesy($OldImg);
//Nyujtas/zsugoritas az aranyok megtartasaval
if ($this->Strech) {
$XRatio=(real)($this->ResizedWidth/$this->Width);
$YRatio=(real)($this->ResizedHeight/$this->Height);
$Ratio=min($XRatio,$YRatio);
$NewWidth=$this->Width*$Ratio;
$NewHeight=$this->Height*$Ratio;
$NewImg=imagecreatetruecolor($NewWidth,$NewHeight);
imagecopyresized($NewImg,$OldImg,0,0,0,0,imagesx($NewImg),imagesy($NewImg),$this->Width,$this->Height);
}
//Kivagas
else {
$NewWidth=$this->Width<$this->ResizedWidth ? $this->Width : $this->ResizedWidth;
$NewHeight=$this->Height<$this->ResizedHeight ? $this->Height : $this->ResizedHeight;
$NewImg=imagecreatetruecolor($NewWidth,$NewHeight);
imagecopyresized($NewImg,$OldImg,0,0,0,0,imagesx($NewImg),imagesy($NewImg),imagesx($NewImg),imagesy($NewImg));
}
//Mentes
if ($NewImg) {
if ($this->FType=="image/gif") {
$NewName=$this->PicDir.$NewName.".gif";
imagegif($NewImg,$NewName);
}
else if ($this->FType=="image/pjpeg" || $this->FType=="image/jpeg") {
$NewName=$this->PicDir.$NewName.".jpg";
imagejpeg($NewImg,$NewName);
}
imagedestroy($NewImg);
}
imagedestroy($OldImg);
}
return $NewName;
}
function Save() {
$ret=copy($this->TmpName,$this->PicDir.$this->Name);
return ret;
}
}
?>