我已經通過將多個圖像複製到新圖像來創建圖像。在我的程序的最後一步中,我試圖將該文件導出到一個文件夾中。嘗試導出圖像時,file_put_contents()發出錯誤
的代碼如下:
<?php
require_once "../shdp/simple_html_dom.php";
$next = "http://www.pidjin.net/2012/08/28/of-my-own/";
$html = file_get_html($next);
$imageList = $html->find('div[class=episode] p img');
$newHeight = 0;
for($iii=0; $iii<count($imageList); $iii++){
$storage[$iii] = $imageList[$iii]->src;
$img[$iii] = imagecreatefromstring(file_get_contents($storage[$iii]));
$width[$iii] = imagesx($img[$iii]);
$height[$iii] = imagesy($img[$iii]);
$newHeight += ($height[$iii] + 30);
}
$newWidth = max($width);
$cummDestHeight = 0;
$export = imagecreatetruecolor($newWidth, $newHeight);
imagefill($export, 0,0, 0xFFFFFF);
for($iii=0;$iii<count($img);$iii++){
imagecopy($export, $img[$iii], 0, $cummDestHeight, 0, 0, $width[$iii], $height[$iii]);
$cummDestHeight += $height[$iii] + 30;
}
$bits = explode('/',$next);
file_put_contents("../pidjin/$bits[5]-$bits[4]-$bits[3].png",$export);
?>
,我收到的錯誤是這樣的:
Warning: file_put_contents(): supplied resource is not a valid stream resource in E:\Web\Comics\pidjin.php on line 54
問題:我不知道我怎樣才能使$導出一個有效的流資源。
所有這些(完全無用的)GD工作的重點是什麼?您從網站獲取圖像,將該圖像的精確副本複製到另一張圖像,然後保存該新圖像。相反,您可以直接保存您提取的原始圖像,而無需解壓縮它。 –