Search in sources :

Example 1 with SVGConverter

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;
}
Also used : FileWriter(java.io.FileWriter) SVGConverter(org.apache.batik.apps.rasterizer.SVGConverter) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with SVGConverter

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);
    }
}
Also used : CoverImageException(org.opencastproject.coverimage.CoverImageException) SVGConverterException(org.apache.batik.apps.rasterizer.SVGConverterException) SVGConverter(org.apache.batik.apps.rasterizer.SVGConverter)

Aggregations

SVGConverter (org.apache.batik.apps.rasterizer.SVGConverter)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 SVGConverterException (org.apache.batik.apps.rasterizer.SVGConverterException)1 CoverImageException (org.opencastproject.coverimage.CoverImageException)1