我有 php 代码来修剪白色外边框和调整大小。当我使用 imagejpeg($newImage) 将它输出到浏览器时它工作正常但是当我尝试使用 imagejpeg($newImage, 'test.jpg') 保存时它不会保存在任何地方。请帮忙?
$im = imagecreatefromjpeg($src);
$bg = imagecolorallocate($im,$rgb,$rgb,$rgb);
// Set the header and output image.
header('Content-type: image/jpeg');
imagetrim($im,$bg);
$width = imagesx($im);
$height = imagesy($im);
$newHeight = $height * $newWidth/$width;
$newImage = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($newImage, $im, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
//imagejpeg($newImage);
//header('Content-Type: image/jpeg');
imagejpeg($newImage, 'test.jpg');
imagejpeg($newImage);
imagedestroy($im);
imagedestroy($newImage);
最佳答案
只是将答案放在答案框中,问题是文件权限不好。 在用 PHP 编写文件之前,不要忘记使用 is_writable 测试要保存文件的位置。
关于PHP imagejpeg 保存文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6672965/