我试图将所有.PNG文件放在一个数组中,并附上其详细信息。
这是我的代码:
$imgs = glob($path . "*.png");
$tab_img = [];
foreach($imgs as $value){
$img_png = imagecreatefrompng($value);
$tab_img['name'] = $value;
$tab_img['width'] = imagesx($img_png);
$tab_img['height'] = imagesy($img_png);
}
print_r($tab_img);
以下是显示内容:
Array
(
[name] => ./sprite.png
[width] => 300
[height] => 300
)
它只在文件夹中显示图像,而事实上,还有更多。。。
在每个循环中,您都要覆盖数组中的相同元素,您应该构建图像数据,然后将其添加到数组中。。。
$img_png = imagecreatefrompng($value);
$tab_img[] = [
'name' => $value,
'width' => imagesx($img_png),
'height' => imagesy($img_png),
];