function ResizeImg2($strSourceImagePath, $strDestImagePath, $intMaxWidth = 200, $intMaxHeight = 200)
{
$intImgWidth = $arrImageProps[0];
$intImgHeight = $arrImageProps[1];
$intImgType = $arrImageProps[2];
switch( $intImgType) {
case 1: $rscImg = ImageCreateFromGif($strSourceImagePath); break;
case 2: $rscImg = ImageCreateFromJpeg($strSourceImagePath); break;
case 3: $rscImg = ImageCreateFromPng($strSourceImagePath); break;
default: return false;
}
if ( !$rscImg) return false;
if ($intImgWidth > $intImgHeight) {
$fltRatio =
floatval($intMaxWidth /
$intImgWidth);
} else {
$fltRatio =
floatval($intMaxHeight /
$intImgHeight);
}
$intNewWidth =
intval($fltRatio *
$intImgWidth);
$intNewHeight =
intval($fltRatio *
$intImgHeight);
$rscNewImg = ImageCreate($intNewWidth, $intNewHeight);
if (!ImageCopyResized($rscNewImg, $rscImg, 0, 0,0, 0, $intNewWidth, $intNewHeight, $intImgWidth, $intImgHeight)) return false;
switch($intImgType) {
case 1: $retVal = ImageGIF($rscNewImg, $strDestImagePath); break;
case 3: $retVal = ImagePNG($rscNewImg, $strDestImagePath); break;
case 2: $retVal = ImageJPEG($rscNewImg, $strDestImagePath, 90); break;
default: return false;
}
ImageDestroy($rscNewImg);
return true;
}
// Тест:
$strTestImgPath =
dirname(__FILE__).
'/testimg.gif';
$strDestImgPath =
dirname(__FILE__).
'/testimg.preview.gif';
print (int
)ResizeImg2
($strTestImgPath,
$strDestImgPath,
300,
300);