rewrite all, now use DOMDocument and Imagick, less code, more elastic, native class