Lib file editing to work with DOMDocument

Lib file is edited to work with DOMDocument. New function takes chapter
and changes all image tags to p tag with content of an alt attribute of
an image file. Output length is handled after removing images. Also
function is used for encoding conversion (Croatian characters).