Version 1
function changeSize($image, $height, $width)
{
@$type = end(explode(".", $image));
if ($type=="jpg"||$type=="jpeg"||$type=="png"||$type=="gif"||$type=="bmp")
{
if ($height>$width) $max = $width;
else $max = $height;
list($iheight, $iwidth) = getimagesize($image);
if ($iheight>$iwidth) $h = $iheight;
else $h = $iwidth;
$p = $h/$max;
if ($h==$iheight)
{
$nheight = $max;
$nwidth = round(($iheight/$iwidth)*$max);
}
else
{
$nwidth = $max;
$nheight = round(($iwidth/$iheight)*$max);
}
echo "<img src='$image' width='$nwidth' height='$nheight' />";
}
else{
echo "The image is not supported!";
}
}
Version 2
function changeSize($image, $height, $width)
{
$type = substr($image, strrpos($image, ".") +1);
if ($type=="jpg"||$type=="jpeg"||$type=="png"||$type=="gif"||$type=="bmp")
{
if ($height>$width) $max = $width;
else $max = $height;
list($iwidth, $iheight) = getimagesize($image);
if ($iheight<=500 && $iwidth<=500)
{
if ($iheight>$iwidth) $h = $iheight;
else $h = $iwidth;
$p = $max/$h;
$nheight = round($iheight*$p);
$nwidth = round($iwidth*$p);
echo "<img src='$image' width='$nwidth' height='$nheight' />";
}
else echo "File too big.";
}
}
