I'm attempting to create a build process that will base64 encode the images in my CSS file. I use rhino for my build process so natural thought was to just do this after I get done building in rhino.
So far I've got the image reading done but getting stuck at the Base64 part ... Everything I try in JavaScript gets mad about the byte[] and everything in Java I try has problems with the Rhino.
Since its rhino I'm limited on the libraries I can use and can't use the apache commons.
Anyone got any ideas?
prodcss = prodcss.replace(/url\(['"]*([^"')]*)['"]*\)/g, function(match) {
var path = "build/" + match.substring(4, match.length - 1);
// Read the image to a byte[]
var file = new java.io.File(path);
var bufferedImage = javax.imageio.ImageIO.read(file);
var raster = bufferedImage.getRaster();
var data = raster.getDataBuffer().getData();
var base64 = ''; // Whats the best way to accomplish this ...
return "url(data:image/png;base64," + base64 + ")";
});
Appreciate the help.