I want to generate a png from a svg string with this code:
try {
PNGTranscoder coder = new PNGTranscoder();
StringReader reader = new StringReader(getSVG());
TranscoderInput input = new TranscoderInput(reader);
FileOutputStream outputStream = new FileOutputStream("tmp/tmp.png");
TranscoderOutput transcoderOutput = new TranscoderOutput(outputStream);
try{
coder.transcode(input, transcoderOutput);
}finally{
reader.close();
outputStream.close();
}
} catch (Exception e) {
ErrorHandler.getInstance().handle(e);
}
But if i run the code, i get an exception because an uri cant be opend because it is corrup or unsupported:
org.apache.batik.bridge.BridgeException: null:0
The URI "https://cdn.discordapp.com/avatars/xxx/xxx.png"
on element <image> can't be opened because:
JDK URL is corrupt or unsupported variant
at org.apache.batik.bridge.UserAgentAdapter.getBrokenLinkDocument(UserAgentAdapter.java:449)
at org.apache.batik.bridge.SVGImageElementBridge.createRasterImageNode(SVGImageElementBridge.java:604)
at org.apache.batik.bridge.SVGImageElementBridge.createImageGraphicsNode(SVGImageElementBridge.java:327)
at org.apache.batik.bridge.SVGImageElementBridge.buildImageGraphicsNode(SVGImageElementBridge.java:177)
at org.apache.batik.bridge.SVGImageElementBridge.createGraphicsNode(SVGImageElementBridge.java:119)
[...]
While converting this svg: https://hastebin.com/mamudofira.xml
The image url is replaced for privacy but its working!
I fixed it myself by first downloading the image as base64 string and then setting it as xlink:href
in the svg.