public void generateDataUriCss ( String dir ) throws IOException { final String path = ( dir == null ) ? "" : dir + "/" ; final PrintWriter out = new PrintWriter ( path + "DataUriCss.html" ) ; try { out . append ( "<html>\n<head>\n\t<style>" ) ; for ( OptimizerResult result : results ) { final String name = result . fileName . replaceAll ( "[^A-Za-z0-9]" , "_" ) ; out . append ( ' ' ) . append ( name ) . append ( " {\n" ) . append ( "\tbackground: url(\"data:image/png;base64," ) . append ( result . dataUri ) . append ( "\") no-repeat left top;\n" ) . append ( "\twidth: " ) . append ( String . valueOf ( result . width ) ) . append ( "px;\n" ) . append ( "\theight: " ) . append ( String . valueOf ( result . height ) ) . append ( "px;\n" ) . append ( "}\n" ) ; } out . append ( "\t</style>\n</head>\n<body>\n" ) ; for ( OptimizerResult result : results ) { final String name = result . fileName . replaceAll ( "[^A-Za-z0-9]" , "_" ) ; out . append ( "\t<div id=\"" ) . append ( name ) . append ( "\"></div>\n" ) ; } out . append ( "</body>\n</html>" ) ; } finally { if ( out != null ) { out . close ( ) ; } } }
Get the css containing data uris of the images processed by the optimizer