简体   繁体   English

PHP imagejpeg 保存文件不起作用

[英]PHP imagejpeg save file doesn't work

I have php code to trim white outer border and resize.我有 php 代码来修剪白色外边框并调整大小。 When I use imagejpeg($newImage) to output it the browser it works fine but when I try to save to using imagejpeg($newImage, 'test.jpg') it doesn't get saved anywhere.当我使用 imagejpeg($newImage) 到 output 时,它的浏览器工作正常,但是当我尝试保存到使用 imagejpeg($newImage, 'test.jpg') 时,它不会保存在任何地方。 Help please?请帮忙?

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

Just to put an answer in the answer box the problem is that the file permissions were not good.只是为了在答案框中输入答案,问题是文件权限不好。 Before writing a file in PHP, do not forget to test the place you want to save files by using is_writable在 PHP 中写入文件之前,不要忘记使用is_writable测试要保存文件的位置

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

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