簡體   English   中英

保存imagejpeg輸出文件

[英]saving imagejpeg output the file

我在這里缺少什么嗎? 如果我更改imagejpeg($thumb, $newImage); imagejpeg($thumb); 它回顯了許多不可讀的字符。 縮略圖目錄存在。

我的最終目的是復制較低質量的圖像。

$filename = $imageDirectory . '/1.jpg';
$percent = 0.5;
$newImage = $imageDirectory . '/thumbs/1.jpeg';    
echo "image: <br>";
echo $filename;
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;    
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);    
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);    
// Output
imagejpeg($thumb, $newImage);

更新:我現在意識到第二個參數必須是具有新名稱的圖像位置。 所以...我已經重新定義了$ newImage。 路徑很好...如果我手動將名為1.jpg的圖像上傳到該位置,則該路徑中存在該圖像。

如果要將圖像輸出到瀏覽器,則必須為響應添加正確的Content-Type標頭:

header('Content-Type: image/jpeg');
imagejpeg($yourimage);

請檢查文檔中第一個示例以獲取更多信息。 如果要在輸出到瀏覽器之前降低質量,請檢查第三個示例。

暫無
暫無

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

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