Fix for-loop bug in image viewer. See #12303
Merge pull request #2573 from will-moore/rebased/dev_5_0/viewer_save_apply_12303

Fix for-loop bug in image viewer. See #12303 (rebased onto dev_5_0)