简体   繁体   English

调整大小后出现黑色图像

[英]Black images after resizing

Here is my code : 这是我的代码:

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

//....

All is working fine. 一切正常。 Except that my pictures are completely black. 除了我的照片是全黑的。 The aim is to reduce their width and height by dividing them by 4.08. 目的是通过将它们除以4.08来减小其宽度和高度。 Know that uploaded image have width equal to 3264 px and height equal to 2448 px. 知道上传的图片的宽度等于3264像素,高度等于2448像素。 Maybe it is too much? 也许太多了?

imagecreatefromjpeg() takes only 1 parameter, the path to the filename (Either local path or URL). imagecreatefromjpeg()仅采用1个参数,即文件名的路径(本地路径或URL)。 You're giving it two parameters. 您给它两个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM