dsplos5731 2014-04-24 14:02
浏览 7

功能php变量未知

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.

  • 写回答

3条回答 默认 最新

  • duanhuan8983 2014-04-24 14:10
    关注

    Looking at following part, it becomes pretty clear:

    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");
    

    translate it to values and you will see ..

    if ($max < max($sw, $sh)) {
            if (600 > 600)
                $new = array($max_em . "em", "auto");
            if (600 < 600)
                $new = array("auto", $max_em . "em");
            $addclass = true;
            // None of the above ifs meet the case of 600x600 !!!!!
            // ----------------------------------------------------
        } else
            $new = array("auto", "auto");
    
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备