Fix an infinite loop with duplicate folder names
Handle images defined by embedded data

Fix issue 265