Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feemarker writing images to html

is there anyway to write image in freemarker instead of giving link as

<img src="${pathToPortalImage}

Note : cant we use otputstream or something in freemarker ?

like image 263
Janith Avatar asked Nov 12 '12 06:11

Janith


1 Answers

A great example above. But with JAVA 8 we can do something like this:

Path path = Paths.get("image.png");
byte[] data = Files.readAllBytes(path);
byte[] encoded = Base64.getEncoder().encode(data);
String imgDataAsBase64 = new String(encoded);
String imgAsBase64 = "data:image/png;base64," + imgDataAsBase64;
like image 52
Greg Avatar answered Oct 13 '22 20:10

Greg