Image preview in menus

You could improve readability a bit if you move this "isValid" statement up a bit and return nil after logging the error. The long else part could be indented back one level so you don't have to think in more code branches. In case isValid can be determined already after the image assignment move it to line 301.