rewritten in pure c/imagemagick