public static function resize($strFileName = "", $intWidth = 100, $intHeight = 75, $intTemplate = RESIZE_EXACT, $intQuality = 75, $blnOverwrite = FALSE, $strName = "", $blnToScreen = FALSE, $blnGrayscale = FALSE) { $strReturn = $strName; if (empty($strReturn)) { if (!$blnOverwrite) { //*** Generate a random name. $strExtension = self::getExtension(basename($strFileName)); $strReturn = dirname($strFileName) . "/{$intWidth}x{$intHeight}_" . basename($strFileName, $strExtension) . "_" . strtotime("now") . "{$strExtension}"; } else { $strReturn = $strFileName; } } $objEditor = new ImageEditor(basename($strFileName), dirname($strFileName) . "/"); switch ($intTemplate) { case RESIZE_CROP: //*** Don't blow the image up if it is smaller then the destination. if ($intWidth > $objEditor->getWidth() && $intHeight > $objEditor->getHeight()) { //*** Skip the resize. } else { $destX = ($objEditor->getWidth() - $intWidth) / 2; $destY = ($objEditor->getHeight() - $intHeight) / 2; $objEditor->crop(round($destX), round($destY), $intWidth, $intHeight); } break; case RESIZE_FIT_CROP: //*** Resize the image to fit into the boundary box. //*** Portrait source. $destWidth = $intWidth; $destHeight = $destWidth / $objEditor->getWidth() * $objEditor->getHeight(); if ($destHeight < $intHeight) { //*** Landscape source. $destHeight = $intHeight; $destWidth = $destHeight / $objEditor->getHeight() * $objEditor->getWidth(); } //*** Don't blow the image up if it is smaller then the destination. if (round($destWidth) > $objEditor->getWidth() && round($destHeight) > $objEditor->getHeight()) { //*** Skipt the resize. $destX = ($objEditor->getWidth() - $intWidth) / 2; $destY = ($objEditor->getHeight() - $intHeight) / 2; $objEditor->crop(round($destX), round($destY), $intWidth, $intHeight); } else { $objEditor->resize(round($destWidth), round($destHeight)); $destX = ($objEditor->getWidth() - $intWidth) / 2; $destY = ($objEditor->getHeight() - $intHeight) / 2; $objEditor->crop(round($destX), round($destY), $intWidth, $intHeight); } break; case RESIZE_DISTORT: //*** Don't blow the image up if it is smaller then the destination. if ($intWidth > $objEditor->getWidth() && $intHeight > $objEditor->getHeight()) { //*** Skipt the resize. } else { $objEditor->resize($intWidth, $intHeight); } break; case RESIZE_EXACT: $destWidth = $intWidth; $destHeight = $destWidth / $objEditor->getWidth() * $objEditor->getHeight(); if ($destHeight > $intHeight) { //*** Landscape source. $destHeight = $intHeight; $destWidth = $destHeight / $objEditor->getHeight() * $objEditor->getWidth(); } //*** Don't blow the image up if it is smaller then the destination. if (round($destWidth) > $objEditor->getWidth() && round($destHeight) > $objEditor->getHeight()) { //*** Skipt the resize. } else { $objEditor->resize(round($destWidth), round($destHeight)); } break; } if ($blnGrayscale) { $objEditor->grayscale(); } if (!empty($strReturn)) { if ($blnToScreen) { //*** Return image. $objEditor->outputImage($intQuality); } else { //*** Write file to disk. $objEditor->outputFile(basename($strReturn), dirname($strReturn) . "/", $intQuality); } } return $strReturn; }
require_once "../lib/class.image_resize.php"; $objImageupload = new imageFileUpload(); $objImageupload->tag_name = "file_name"; $a_tempFileName = explode(".", strtolower($_FILES['file_name']['name'])); $objImageupload->file_name = $a_tempFileName[0] . "." . $a_tempFileName[1]; $newFileName = $objImageupload->file_name; $objImageupload->storing_directory = IMAGE_UPLOAD_PATH; $objImageupload->image_extensions = "jpg,gif,png,jpeg"; if (false == $objImageupload->upload()) { $error = $objImageupload->errorMsg(); echo "Error : " . $error; } $outputFileName = $objImageupload->file_name; $destinationPath = $objImageupload->storing_directory; $objImageEditor = new ImageEditor($objImageupload->file_name, $objImageupload->storing_directory); $objImageEditor->resizeInProportion($objImageEditor->getWidth(), $objImageEditor->getHeight(), 320); $objImageEditor->outputFile($outputFileName, $destinationPath); chmod($objImageupload->storing_directory . $objImageupload->file_name, 0777); /* $image_height = 320; $image_width = 400; $arfilename = $objUpload->upload($id,'file_name',IMAGE_UPLOAD_PATH,'jpeg,gif,png,JPG,JPEG,jpeg'); $filename = $arfilename[0]; //$objUpload->smart_resize_image(IMAGE_UPLOAD_PATH.$arfilename[0],$image_height,$image_width,IMAGE_UPLOAD_PATH,true,$arfilename[0],false); */ // $image->load(IMAGE_UPLOAD_PATH.$arfilename[0]); // $image->resize(320,316); // $image->save(IMAGE_UPLOAD_PATH.$arfilename[0]); // $WaterMarkText = "fototime.com"; // $image->watermarkImage (IMAGE_UPLOAD_PATH.$arfilename[0], $WaterMarkText, //IMAGE_UPLOAD_PATH.$arfilename[0]); include "../classes/imageslice.php";