Skip to content

Instantly share code, notes, and snippets.

@mstred
Created March 15, 2013 19:49
Show Gist options
  • Save mstred/5172606 to your computer and use it in GitHub Desktop.
Save mstred/5172606 to your computer and use it in GitHub Desktop.
Content file to Data-URI file generator in Groovy
def path = "" //path to input file directory
def input = new File("${path}/file.png") //example
def mime = new javax.activation.MimetypesFileTypeMap().getContentType(input)
def content = "data:${mime};base64,${input.bytes.encodeBase64().toString()}"
def output = new java.io.FileWriter("${path}/${input.name}.datauri")
def info = "${input.name} -> ${((input.size() / 1024f) / 1024f)} MB \nMime-type: ${mime}"
println info
output.write(content)
output.close()
/* Clipboard
java.awt.Toolkit.defaultToolkit.systemClipboard.setContents(new java.awt.datatransfer.StringSelection(content), null) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment