I'm generating a website with JDenticon using this code (test.html):
<!DOCTYPE HTML>
<html>
<head>
<title>Test</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/jdenticon/1.3.2/jdenticon.min.js" async></script>
<svg width="200" height="200" data-jdenticon-hash="ff8adece0631821959f443c9d956fc39">
Fallback text for browsers not supporting inline svg</svg>
</body>
</html>
I want to get the image generated in this code to be accesible by a Java desktop application and want it to be saved on my PC. Is this possible and maybe also with changing the hascode (ff8adece0631821959f443c9d956fc39)
And whats the code for it?
Edit #1:
I've found something in the API of JDenticon that looks like this and is used for .NET Framework:
var engine = new Jurassic.ScriptEngine();
engine.ExecuteFile("<path to jdenticon.js>");
engine.SetGlobalValue("size", 200);
engine.SetGlobalValue("hash", "ff8adece0631821959f443c9d956fc39");
var svg = engine.Evaluate<string>("jdenticon.toSvg(hash, size)");
File.WriteAllText("testicon.svg", svg);
I wanted to do something like this in Java and found Java ScriptEngine (Tutorials: Oracle). But I don't know how to use it, right now my code looks like this:
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.put("size", 200);
engine.put("hash", "ff8adece0631821959f443c9d956fc39");
String svg = (String) engine.eval(new java.io.FileReader("C:/jdenticon.js"));
This obviously won't work because it does not call the jdenticon.toSvg(hash, size) method in the jdenticon.js file. So if someone has an idea on how to solve the problem with thisit would be very nice.