Yes, as you don't have any control about how images are actually being positioned/displayed both worst case scenarios are being considered - which is all images in one line, or all images in one row.
If you have a better idea, let me know
I thought about calculating the max. space taken, but that won't work too well, if you define 100x500 (=5000 pixel) one could use a 1x5000 iamge then ...