This is a much easier way to do it now.
All you need it this code
=image("https://flagcdn.com/w160/" & lower(**codefield**) & ".png")
Just point codefiled to you 2 letter country code and it works.
Sorry for the old way, was way too complicated.