Fix deleting of images. Fixes #3562