function scale($src) {
$max = 350;
if (!isset($max, $src))
return;
$src = str_replace(" ", "%20", $src[1]);
$info = @getimagesize($src);
$sw = $info[0];
$sh = $info[1];
$addclass = false;
$max_em = 0.06 * $max;
if ($max < max($sw, $sh)) {
if ($sw > $sh)
$new = array($max_em . "em", "auto");
if ($sw < $sh)
$new = array("auto", $max_em . "em");
$addclass = true;
} else
$new = array("auto", "auto");
$id = mt_rand(0000, 9999);
if ($new[0] == "auto" && $new[1] == "auto")
$img = "<img src=\"" . $src . "\" border=\"0\" alt=\"\" />";
else
$img = "<img id=\"r" . $id . "\" border=\"0\" alt=\"\" src=\"" . $src . "\" " . ($addclass ? "class=\"resized\"" : "") . " style=\"width:" . $new[0] . ";height:" . $new[1] . ";\" />";
return $img;
}
I have this function to resize images. It does the job when images are bigger, but when they are 600x600 for example, i get Notice: Undefined variable: new in line
if ($new[0] == "auto" && $new[1] == "auto")
and
$img = "<img id=\"r" . $id . "\" border=\"0\" alt=\"\" src=\"" . $src . "\" " . ($addclass ? "class=\"resized\"" : "") . " style=\"width:" . $new[0] . ";height:" . $new[1] . ";\" />";
For this case, else, $new should be $new = array("auto", "auto");
, but it's not recognized.