I have an upload form which accepts multiple file uploads. Each file is 32px x 32px and I am trying to generate an image which contains each image in a grid. every row allows for 30 tiles and the column size is calculated based on the amount of tiles uploaded. For example if there's 120 images there would be 4 columns.
The issue i'm facing is, I cannot seem to calculate the position of each tile in imagecopy. I'm getting the error: "foreach() argument must be of type array|object, string given" for the 2nd foreach loop.
<?php
$num_files = count($_FILES['myFiles']['tmp_name']);
$image = imagecreate(960, ceil(round(30 / $num_files)));
foreach($_FILES['myFiles']['tmp_name'] as $row => $columns) {
foreach($columns as $col => $filename) {
$tile = imagecreatefrompng($filename);
imagecopy($image, $tile, $row * 32, $col * 32, 0, 0, 32, 32);
}
}
header('Content-Type: image/png');
imagepng($image);