Attached is a very rough first attempt at a MathML-->gif filter. It uses the xsl style sheets downloaded from http://www.raleigh.ru/MathML/mmltex together with the Xalan XSLT processor from the Apache XML Project at http://xml.apache.org/xalan-c/ to transform the MathML to TeX, then uses mimetex.cgi to convert the TeX to gif files. Everything used is open source, except for a library from the Intel C compiler used by Xalan. The Intel C compiler is not open source, but it there is a free (as in beer) download for Linux (sans support).
PS to Martin: weblib.php is missing the MathML tag <msup>