调整大小后的黑色图像

时间:2017-04-12 13:27:14

标签: php image gd

这是我的代码:

    foreach($_FILES as $key=>$photo){
                if ($check[$key] == 'OK'){
                $path = '../images/chevaux/' . $_POST['horseName'] . '_' . $horseID . '/' . $key . '.' . $file_extension;
                $folder = '../images/chevaux/' . $_POST['horseName'] . '_' . $horseID;
                if (!is_dir($folder))
                {
                    mkdir($folder);
                }          

                    $filename = $photo['tmp_name'];
                    $percent = 4.08;

                    list($width, $height) = getimagesize($filename);
                    $newwidth = $width / $percent;
                    $newheight = $height / $percent;

                    $thumb = imagecreatetruecolor($newwidth, $newheight);
                    $source = imagecreatefromjpeg($filename, $path);

                    imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

                    imagejpeg($thumb, $path);

//....

一切正常。除了我的照片是完全黑色的。目的是通过将它们除以4.08来减小它们的宽度和高度。知道上传的图像宽度等于3264像素,高度等于2448像素。也许这太过分了?

1 个答案:

答案 0 :(得分:1)

imagecreatefromjpeg()只接受1个参数,即文件名的路径(本地路径或URL)。你给它两个参数。