>Народ, как ресайзануть из любого размера имаг в ширину 800, и высоту
>пропорционально ширине? resizeImage ($src, $dest, $newHeight, 800)
function resizeImage ($src, $dest, $newHeight, $newWidth)
{
/*if ( $dest )
{
fopen($dest, "w") ||
die("Can not write to $dest. Check directory permissions!");
}*/
$imgInfo = getimagesize($src);
$width = $imgInfo[0]; $height = $imgInfo[1];
$file_type = $imgInfo[2];
if($width <= $newWidth)
{
$newWidth = 0;
}
else
{
$newHeight = ($newWidth*$height)/ $width;
}
if ( $newHeight || $newWidth )
{
if ( $newHeight && $newWidth )
{
$width = $newWidth;
$height = $newHeight;
} else {
if ( $newWidth == "0" )
{
$ratio = (intval(($width / $newWidth) * 100)) / 100;
$width = (intval(($width / $ratio) * 100)) / 100;
$height = (intval(($height / $ratio) * 100)) / 100;
} else {
$ratio = (intval(($width / $newHeight) * 100)) / 100;
$width = (intval(($width / $ratio) * 100)) / 100;
$height = (intval(($height / $ratio) * 100)) / 100;
}
}
}
$destimg=ImageCreateTrueColor($width,$height);
switch ($file_type)
{
case 1:
$srcimg = imagecreatefromgif($src);
if (function_exists(ImageGIF))
{
$imgType = "gif";
} else {
$imgType = "jpeg";
}
break;
case 2:
$srcimg = imagecreatefromjpeg($src);
$imgType = "jpeg";
break;
case 3:
$srcimg = imagecreatefrompng($src);
$imgType = "png";
break;
default:
break;
}
ImageCopyResized($destimg,$srcimg,0,0,0,0,$width,$height,ImageSX($srcimg),ImageSY($srcimg));
if ( !$dest ) { header ("Content-type: image/$imgType"); }
switch ($file_type)
{
case 1:
if (function_exists(ImageGIF))
{
if ( $dest) { imagegif ($destimg, $dest); } else { imagegif($destimg); }
} else {
if ( $dest) { imagejpeg ($destimg, $dest); } else { imagejpeg($destimg); }
}
break;
case 2:
if ( $dest) { imagejpeg ($destimg, $dest); } else { imagejpeg($destimg); }
break;
case 3:
if ( $dest) { imagepng ($destimg, $dest); } else { imagepng($destimg); }
break;
default:
break;
}
imagedestroy ($srcimg);
imagedestroy ($destimg);
}