PHP imagejpeg 保存文件不起作用

2024-03-04

我有 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 编写文件之前,不要忘记使用以下命令测试要保存文件的位置是可写的 http://php.net/manual/fr/function.is-writable.php

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PHP imagejpeg 保存文件不起作用 的相关文章

随机推荐