@thor
After that, you check if the number of attachments is dividable by the row number:
if it is, then you'll equally split the attachments between the rows, you divide number_attachments/number_rows to get how many;
if it isn't, then you have one row that has rounded_down(number_attachments/number_rows), and the rest are rounded_up(number_attachments/number_rows).