require_once("functions.php"); /*-----------------------------------------------\ ::::::::::::::::URL VARIABLES:::::::::::::::::::: $pFile - filename of image to modify. (Required) $pType - options: thumb, scale $pDir - custom directory of image source(optional) $pWid - desired image width $pHei - desired image height ::::::::::::::::::::::::::::::::::::::::::::::::: \-----------------------------------------------*/ //check if filename is present if(isset($_GET['pFile'])){ $pFile = $_GET['pFile']; } //check if thumb or scale if(!isset($_GET['pType'])){ $pType = "scale"; }else{ $pType = $_GET['pType']; } //check if directory is defined if(!isset($_GET['pDir'])){ if($pType == "thumb"){ $sDir = "../images/thumbnails/"; } $pDir = "../images/uploads/"; }else{ $pDir = "../" . $_GET['pDir']; } //check if file exists if(!file_exists($pDir . $pFile) || $pFile == ""){ echo '
File Not Found!'; } //define variables $pFileUrl = $pDir . $pFile; $pExt = findexts($pFile); function generatePhoto($imgFile, $imgType, $imgExt){ /*--------------------------------------------/ $cWidth/Height = Container Dimensions $newWidth/Height = Scaled Dimensions $iWidth/Height = File Dimensions /--------------------------------------------*/ switch($imgExt){ case 'gif': $image = imagecreatefromgif($imgFile); break; case 'jpg': $image = imagecreatefromjpeg($imgFile); break; case 'png': $image = imagecreatefrompng($imgFile); break; default : return "Unsupported picture type!"; } //defaults if(!isset($_GET['pWid']) && $imgType == "thumb"){ $cWidth = 160; } else if(!isset($_GET['pWid'])){ $cWidth = 1000; } else{ $cWidth = $_GET['pWid']; } if(!isset($_GET['pHei']) && $imgType == "thumb"){ $cHeight = 120; } else if(!isset($_GET['pHei'])){ $cHeight = 600; } else { $cHeight = $_GET['pHei']; } list($iWidth, $iHeight) = getimagesize($imgFile); $iRatio = $iWidth / $iHeight; if($imgType == "thumb"){ //scale if($iWidth < $iHeight){ $newWidth = $cWidth; $newHeight = intval($newWidth / $iRatio); }else{ $newHeight = $cHeight; $newWidth = intval($newHeight * $iRatio); } //generate image $img = imagecreatetruecolor($cWidth, $cHeight); //$tc = imagecolorallocate($img, 255, 255, 255); //$st = "Width: " . $sWidth . " | Height: " . $sHeight; //$st1 = "x: " . $iX . " | y: " . $iY; //imagestring($img, 1, 5, 5, $st, $tc); //imagestring($img, 1, 5, 20, $st1, $tc); }else if($iWidth > $cWidth || $iHeight > $cHeight){ if($iWidth > $iHeight){ $newWidth = $cWidth; $newHeight = intval($newWidth / $iRatio); }else{ $newHeight = $cHeight; $newWidth = intval($newHeight * $iRatio); } //generate image $img = imagecreatetruecolor($newWidth, $newHeight); }else{ //actual size $newWidth = $iWidth; $newHeight = $iHeight; //generate image $img = imagecreatetruecolor($newWidth, $newHeight); } imagecopyresampled($img, $image, 0, 0, 0, 0, $newWidth, $newHeight, $iWidth, $iHeight); return $img; } if($pExt == 'jpeg') $pExt = 'jpg'; switch($pExt){ case 'gif': header("Content-Type: image/gif"); break; case 'jpg': header("Content-Type: image/jpeg"); break; case 'png': header("Content-Type: image/png"); break; default : echo '
Error displaying this file'; } $img = generatePhoto($pFileUrl, $pType, $pExt); switch($pExt){ case 'gif': imagejpeg($img); break; case 'jpg': imagejpeg($img, null, 90); break; case 'png': imagejpeg($img, null, 90); break; default : echo '
Error displaying this file'; } ?>