use of org.apache.batik.apps.rasterizer.SVGConverter in project xwiki-platform by xwiki.
the class SVGPlugin method getSVGImage.
public byte[] getSVGImage(int hashCode, String content, String extension, int height, int width) throws IOException, SVGConverterException {
File dfile = getTempFile(hashCode, "svg");
if (!dfile.exists()) {
FileWriter fwriter = new FileWriter(dfile);
fwriter.write(content);
fwriter.flush();
fwriter.close();
}
File ofile = getTempFile(hashCode, extension);
// TODO implement conversion HERE
SVGConverter conv = new SVGConverter();
// TODO PNG ONLY
conv.setDestinationType(DestinationType.PNG);
conv.setDst(ofile);
conv.setHeight(height);
conv.setWidth(width);
String[] sources = { dfile.getAbsolutePath() };
conv.setSources(sources);
conv.execute();
FileInputStream fis = new FileInputStream(ofile);
byte[] result = new byte[(int) ofile.length()];
try {
fis.read(result);
} finally {
IOUtils.closeQuietly(fis);
}
return result;
}
use of org.apache.batik.apps.rasterizer.SVGConverter in project opencast by opencast.
the class AbstractCoverImageService method rasterizeSvg.
protected static void rasterizeSvg(File svgSource, File pngResult) throws CoverImageException {
SVGConverter converter = new SVGConverter();
converter.setDestinationType(DestinationType.PNG);
converter.setDst(pngResult);
converter.setSources(new String[] { svgSource.getAbsolutePath() });
try {
log.debug("Start converting SVG to PNG");
converter.execute();
} catch (SVGConverterException e) {
log.warn("Error while converting the SVG to a PNG: {}", e.getMessage());
throw new CoverImageException("Error while converting the SVG to a PNG", e);
}
}
Aggregations