我通过将多个图像复制到新图像中来创建图像。在程序的最后一步中,我尝试将此文件导出到文件夹中。
代码如下:
<?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
Problem:我不确定如何使 $export 成为有效的流资源。
$export 将是一个 GD 图像句柄。这是NOT您可以简单地将其转储到文件中并期望获得 JPG 或 PNG 图像。
为此,你应该这样做
imagepng($export, "../pidjin/$bits etc...");
这将为您创建 .PNG 文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)