if ($typeok)
{
list($w, $h) = getimagesize($saveto);
$tw = $w;
$th = $h;
$max = 100;
if($w > $h && $max < $w)
{
$th = $max / $w * $h;
$tw = $max;
}
elseif ($h > $w && $max < $h)
{
$tw = $max / $h * $w;
$th = $max;
}
elseif ($max < $w)
{
$tw = $th = $max;
}
$tmp = imagecreatetruecolor($tw, $th);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $tw, $th, $w, $h);
imageconvolution($tmp, array(array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1)), 8, 0);
imagejpeg($tmp, $saveto);
imagedestroy($tmp);
imagedestroy($src);
}
if ($typeok) { list($w, $h) = getimagesize($saveto); $tw = $w; $th = $h; $max
Share
The final condition should only be executed in the case that $h = $w and both are > $max.
The first condition fires only when $w is bigger than $h and it needs to be resized. The second will only fire if $h is bigger than $w, and the image needs to be resized. So, the third condition merely checks to see if the image needs to be resized ($w > $max). If it does, you can safely assume that $w = $h because neither of the previous 2 conditions fired (meaning, $w was not bigger, and $h wasn’t bigger. They must be equal).
The only remaining conditions involved ones where $w and $h are less than $max. No resizing needs to be done here, so we don’t bother catching those conditions.
Hope that makes sense!