簡體   English   中英

PHP imagejpeg 保存文件不起作用

[英]PHP imagejpeg save file doesn't work

我有 php 代碼來修剪白色外邊框並調整大小。 當我使用 imagejpeg($newImage) 到 output 時,它的瀏覽器工作正常,但是當我嘗試保存到使用 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測試要保存文件的位置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM