Hook to rename files only works with the first one

What filesize and how many images are we talking here?

I just tested this and several files were renamed, others were not, depending on the number of images it seems. Haven’t debugged this properly yet, but I wonder if this has to do with PHP settings.