Created
July 31, 2013 22:38
-
-
Save seanparsons/6126830 to your computer and use it in GitHub Desktop.
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
import org.apache.commons.codec.binary.Base64 | |
import java.nio.file._ | |
import java.nio.file.attribute._ | |
import scala.collection.mutable.ListBuffer | |
val htmlTemplate = """ | |
<html> | |
<head> | |
<title>Encoded Images!</title> | |
</head> | |
<body> | |
%s | |
</body> | |
</html>""" | |
val filesystem = FileSystems.getDefault | |
val path = filesystem.getPath(".") | |
val matcher = filesystem.getPathMatcher("glob:{**.png,**.jpg,**.gif}") | |
val files = ListBuffer.empty[Path] | |
Files.walkFileTree(path, new SimpleFileVisitor[Path]() { | |
override def visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult = { | |
if (matcher.matches(file)) files += file | |
FileVisitResult.CONTINUE | |
} | |
}) | |
val embeddedImages = files.toList.map(file => """<img src="data:image/png;base64,%s" />""".format(Base64.encodeBase64String(Files.readAllBytes(file)))) | |
Files.write(filesystem.getPath("result.html"), htmlTemplate.format(embeddedImages.mkString).getBytes("UTF-8")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
seems legit ;) #KnowsNothingAboutScala