Hello, I would like to know what's the solution to make a small image, from pieces? In a database, i've stored from 1 to 600 pieces of smaller images, and i would like to put them all in a smaller image. Each small piece has 53 width, 38 height. What should I do to put each image one near other, and after every 50 images to continue showing the images on the next line. Sort of what i want to have in 1 smaller image <img src="img1"><img src="img2">...<img src="img50"><br> Code (markup): Thank you in advance!
There's probably a better way to do this, but this is an easy way with nested loops: $numrows = 12; // number of rows $numcols = 50; // number of images per row // 12 rows x 50 images each = 600 images echo "<table>"; for ($row = 1, $row < $numrows, $row++) { echo "<tr>"; for ($column = 1, $column < $numcols, $column++) { $imagefile = $row*$column; echo "<td><img src=\"img$imagefile.gif\"></td>"; } echo "</tr>"; } echo "</table>"; PHP: You have to do it in a table because most browsers will force the images to wrap themselves without it. There's probably some syntax errors in the above code, but it will do exactly what you want.
There are syntax errors, plus you have the wrong equation to calculate the $imagefile value. Here is a fixed version: <?php $numrows = 12; // number of rows $numcols = 50; // number of images per row // 12 rows x 50 images each = 600 images echo "<table>"; for ($row = 1; $row <= $numrows; $row++) { echo "<tr>"; for ($column = 1; $column <= $numcols; $column++) { $imagefile = (($row-1)*$numcols)+$column; echo "<td><img src=\"img$imagefile.gif\"></td>"; } echo "</tr>"; } echo "</table>"; ?> PHP:
hmm, i want to generate a new image using gd library or other module, standalone, not adding piece by piece in a table.