Heh, checking the number of layers in an image is a non-trivial task - you effectively have to walk up the tree and count them yourself. :)