I tried this code, but it don't work fine.
if I try to transform an image from 1000x5000 or 5000x1000 (i.e.) ,it will not work to resize to the maximum 800x600 proportionally
my code:
function gravaImg($img, $folder, $max_x=800, $max_y=600, $quality=100)
{
list($width,$height) = getimagesize($img['tmp_name']);
if ($width > $max_x or $height > $max_y)
{
if ($height > $width)
{
$tax = $width/$max_x;
$x = $max_x;
$y = $height/$tax;
}
elseif ($width > $height)
{
$tax = $height/$max_y;
$x = $width/$tax;
$y = $max_y;
}
// elseif ($width == $height)
else
{
$tax = $width/$max_x;
$x = $width/$tax;
$tax = $height/$max_y;
$y = $height/$tax;
}
}
else
{
$x = $width;
$y = $height;
}
$redim = imagecreatetruecolor($x,$y);
if($img['type']=='image/png' or $img['type']=='image/x-png')
{
$original = @imagecreatefrompng($img['tmp_name']);
}
elseif($img['type']=='image/gif')
{
$original = @imagecreatefromgif($img['tmp_name']);
}
else{
$original = @imagecreatefromjpeg($img['tmp_name']);
}
chdir($folder);
$nome = md5(time()).'.jpg';
imagecopyresized($redim, $original, 0, 0, 0, 0, $x, $y, $width, $height);
imagejpeg($redim,$nome,$quality);
imagedestroy($redim);
}
what's wrong???
thanks