Shizya
Новичок
продолжаем ресайзить картинки...
Вот функция которая ресайзит картинки:
Масштабирование производится на основе вычисления коэфициэнта пропорции от большей величины (высоты или ширины исходной картинки).
Но ПОЧЕМУ в уменьшенной картинке отображается так мало цветов, что аж смотреть страшно?
Вот функция которая ресайзит картинки:
PHP:
function ResizeImg2($strSourceImagePath, $strDestImagePath, $intMaxWidth = 200, $intMaxHeight = 200)
{
$arrImageProps = getimagesize($strSourceImagePath);
$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;
}
Но ПОЧЕМУ в уменьшенной картинке отображается так мало цветов, что аж смотреть страшно?