0
我有一个包含大约1000个图像URL的XML文件。我想使用PHP创建所有图像的精灵。使用PHP和XML创建1000个图像的CSS-sprite
- XML文件的大小约为30 MB
- 的图像是大约15KB大小
我怎样才能得到它呢?
这里是我的代码(我得到致命错误:让内存大小...):
<?php
$dest = imagecreatefromjpeg('15000x2000.jpg');
$increasing_width = 0;
$increasing_height = 0;
$xmldata = '1000-images.xml';
$open = fopen($xmldata, 'r');
$content = stream_get_contents($open);
fclose($open);
$xml = new SimpleXMLElement($content);
foreach ($xml->xpath('//image') as $image) {
$src = imagecreatefromjpeg('test/' . $image->picture->attributes() . '.jpg');
if ($increasing_width == '15000') {
$increasing_width = '0';
$increasing_height += 200;
}
imagecopymerge($dest, $src, $increasing_width, $increasing_height, 0, 0, 150, 200, 100);
}
imagejpeg($dest, '15000x2000.jpg');
?>
分配更多的内存?听起来这将是一个巨大的图像(像素明智),这将需要一个公吨的内存。 – deceze 2012-07-09 11:30:04
我有两个问题:你为什么要将数字与字符串进行比较,以及实际上允许的内存大小有多少? – raina77ow 2012-07-09 11:31:05
记住两点建议:要么增加php.ini中的memory_limit指令,要么使用ImageMagick(http://www.php.net/manual/en/book.imagick.php)库代替gd2 – antoniom 2012-07-09 11:31:16