Hi, nice mod.
Code:
class AttilitusImage{
function vbimghost_imgtype ($val){
$types = array(
1 => '.GIF',
2 => '.JPG',
3 => '.PNG',
4 => '.SWF',
5 => '.PSD',
6 => '.BMP',
7 => '.TIFF',
8 => '.TIFF',
9 => '.JPC',
10 => '.JP2',
11 => '.JPX',
12 => '.JB2',
13 => '.SWC',
14 => '.IFF',
15 => '.WBMP',
16 => '.XBM'
);
if ($val > 16 )
return false;
else
return strtolower($types[$val]);
}
function resize($filename,$imagew,$imageh){
$filepath="$directory/$filename";
$filepath=$filename;
if(!$dime = getimagesize($filepath)){
eval(standard_error("Not an Image"));
}
$fileext=$this->vbimghost_imgtype($dime[2]);
switch ($fileext){
case (".gif"):
$srcImg = imagecreatefromgif($filepath);
$colortrans = imagecolortransparent($srcImg);
$thumbImg = imagecreate($imagew, $imageh);
imagepalettecopy($thumbImg,$srcImg);
imagefill($thumbImg,0,0,$colortrans);
imagecolortransparent($thumbImg,$colortrans);
imagecopyresized($thumbImg,$srcImg,0,0,0,0,$imagew,$imageh,$dime[0],$dime[1]);
imagegif($thumbImg,$filepath);
break;
case (".jpg"):
case (".jpeg"):
$srcImg = imagecreatefromjpeg($filepath);
if (function_exists('imagecreatetruecolor')){
$thumbImg = imagecreatetruecolor($imagew,$imageh);
imagecopyresampled($thumbImg,$srcImg,0,0,0,0,$imagew,$imageh,$dime[0],$dime[1]);
}else{
$thumbImg = imagecreate($imagew,$imageh);
imagecopyresized($thumbImg,$srcImg,0,0,0,0,$imagew,$imageh,$dime[0],$dime[1]);
}
imagejpeg($thumbImg,$filepath,75);
break;
case (".png"):
$srcImg = imagecreatefrompng($filepath);
if (function_exists('imagecreatetruecolor')){
$thumbImg = imagecreatetruecolor($imagew,$imageh);
imagecopyresampled($thumbImg,$srcImg,0,0,0,0,$imagew,$imageh,$dime[0],$dime[1]);
}else{
$thumbImg = imagecreate($imagew,$imageh);
imagecopyresized($thumbImg,$srcImg,0,0,0,0,$imagew,$imageh,$dime[0],$dime[1]);
}
imagepng($thumbImg,$filepath);
break;
default:
return false;
break;
}
imagedestroy($srcImg);
imagedestroy($thumbImg);
return true;
}
function upload($file,$filename,$directory,$maxw,$maxh){
$AllowedExtensions=".jpg|.gif|.jpeg|.png";
$AllowedExtensions=explode("|",strtolower($AllowedExtensions));
$upfilename = str_replace("'","",$file['name']);
$upfilesize = ($file['size']/1024);
$upfiletype = $file['type'];
$upfiletname = $file['tmp_name'];
$upfileerro = $file['error'];
$fileext =trim(strtolower(strrchr($upfilename, '.')));
//fix for getimagesize errors
$tmpname = "tmp_".uniqid($userid).$fileext;
if(move_uploaded_file($upfiletname, $directory."/".$tmpname)){
$upfiletname = $directory."/".$tmpname;
}
if ($upfilename!="")
{
if(!$dime = getimagesize($upfiletname)){
eval(standard_error("Not an Image"));
}
if (!$dime){
eval(standard_error("Error image size not defined"));
}
$fileext = $this->vbimghost_imgtype($dime[2]);
$this->Uploaded_EXT=$fileext;
if(! in_array($fileext,$AllowedExtensions)){
eval(standard_error("Image extension is not allowed."));
}
//If Width or Height are off resize.
if($dime[0] > $maxw)
{
$ResizeRatio=($maxw/$dime[0]);
$NewWidth=$ResizeRatio*$dime[0];
$NewHeight=$ResizeRatio*$dime[1];
$this->resize($upfiletname,$NewWidth,$NewHeight);
}else if($dime[1] > $maxh){
$ResizeRatio=($maxh/$dime[1]);
$NewWidth=$ResizeRatio*$dime[0];
$NewHeight=$ResizeRatio*$dime[1];
$this->resize($upfiletname,$NewWidth,$NewHeight);
}
@copy($upfiletname, $directory."/".$filename.$fileext);
//remove temp file
unlink($upfiletname);
}
}
}