Defensive code around image loading