Created
March 15, 2013 19:49
-
-
Save mstred/5172606 to your computer and use it in GitHub Desktop.
Content file to Data-URI file generator in Groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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