header('Content-Type:image / jpeg')使网站变黑

时间:2018-10-01 11:41:03

标签: php thumbnails

我有一个代码可以像这样:

 switch (strtolower($imgOrginalsize['mime'])) {
            case 'image/jpeg':
                $img = imagecreatefromjpeg($file);
                $new = imagecreatetruecolor($w, $h);
                imagecopyresampled($new, $img, 0, 0, 0, 0, $w, $h, $imgOrginalsize[0], $imgOrginalsize[1]);
                header('Content-Type: image/jpeg'); // when I comment this everything works good, but with this I have a whole black site. What is wrong? In png it doesn't destroy my site.
                imagepng($new, $pathToSave . $file_name, 9);
                imagedestroy($new);
                break;
            case 'image/png':
                $img = imagecreatefrompng($file);
                $new = imagecreatetruecolor($w, $h);
                imagecopyresampled($new, $img, 0, 0, 0, 0, $w, $h, $imgOrginalsize[0], $imgOrginalsize[1]);
                header('Content-Type: image/png');
                imagepng($new, $pathToSave . $file_name, 9);
                imagedestroy($new);
                break;
            default:
                die();
        }

当我将代码标题jpeg添加到整个站点时,整个站点都是黑色的。不会破坏它,一切正常。我看不出我的错误在哪里。网站看起来像这样:

enter image description here

1 个答案:

答案 0 :(得分:2)

这很明显。仔细查看这两行;-)

ipcRenderer.on('set_data', function (event, data) {
    console.log(data);
    $("#seuser_name").text(data);
});

将其更改为正确的内容类型!使用header('Content-Type: image/jpeg'); imagepng($new, $pathToSave . $file_name, 9); http://php.net/manual/en/function.imagejpeg.php