By using the image ID as part of the sort function we ensure a stable order even for images with the same size.