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; }