imagecopyresized()图像尺寸无效?

时间:2012-01-19 22:19:56

标签: php image function

尝试创建图像缩略图时出现以下错误:

Warning: imagecopyresized() [function.imagecopyresized]: Invalid image dimensions in H:\Programs\webserver\root\media\images\inc\func.php on line 160

这是我为完成这项工作而创建的功能:

function create_thumbnail($image_type, $image_height, $image_height, $temp_dir, $thumb_path, $thumb_width, $thumb_height){
    switch($image_type){
        case 'image/jpeg';
            $img =      imagecreatefromjpeg($temp_dir);
            $thumb =    imagecreatetruecolor($thumb_width, $thumb_height);
                        imagecopyresized($thumb, $img, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height);
                        imagejpeg($thumb, $thumb_path, 100);


        break;
        case 'image/png';
            $img =      imagecreatefrompng($temp_dir);
            $thumb =    imagecreatetruecolor($thumb_width, $thumb_height);
                        imagecopyresized($thumb, $img, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height );
                        imagepng($thumb, $thumb_path, 100);

        break;
        case 'image/gif';
            $img =      imagecreatefromgif($temp_dir);
            $thumb =    imagecreatetruecolor($thumb_width, $thumb_height);
                        imagecopyresized($thumb, $img, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height );
                        imagegif($thumb, $thumb_path, 100);

        break;
    }

}

使用方法如下:

// Create the new thumbnail dimensions
                        list($thumb_width, $thumb_height) = thumb_dimensions($case, $image_width, $image_height);

                        // Create the thumbnails
                        create_thumbnail($image_type, $image_height, $image_height, $temp_dir, $thumb_path, $thumb_width, $thumb_height);

拇指尺寸为宽度:100px,高度:99px;

1 个答案:

答案 0 :(得分:4)

函数定义中的错误:

function create_thumbnail($image_type, $image_height, $image_height, ...
                                           ^^------dupe----^^

表示$image_width未定义,可能评估为0。

同样适用于最后的create_thumbnail()示例调用 - 两个image_heights,没有image_width。