Allow to set custom ratio for images from xml file.

It avoids crashes and memory leaks after changing resolution.