PHP imagejpeg 保存文件不起作用

标签 php jpeg

我有 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/

相关文章:

php - laravel 5.4 MIME 自定义错误消息不起作用?

Fedora + Zend Server CE 上的 PHP 默认时区问题

php - Class::getInstance 的起源/解释?

php - 从数据库填充下拉菜单时出错

iPhone 故障保护多个文件下载

image - VBA:复制单元格,粘贴为图片,然后另存为图片?

php - 如何从批处理文件执行 codeigniter Controller

Perl:将 MP3 ID3-Tags 的封面保存到外部 JPG 文件中

java - 如何在不解码整个图像的情况下知道 jpeg 格式 (android)

html - 输入选项(单选框和复选框)有带图标的按钮