Talk:SVG benchmarks

From MediaWiki.org

Jump to: navigation, search

Maybe you want to try again with this:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;

import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.PNGTranscoder;

/**
 * Argument: Filename of a file with two filenames on each line, separated by a tab character. The
 * first filename is the url of an input file, the second the name of the output file.
 */
public class BatikServ {
   public static void main(String args[]) throws Exception {
      if (args.length < 1) {
         System.err.println("Usage: java BatikServ <urlfile>");
         System.exit(1);
      }

      File urlfile = new File(args[0]);
      BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(urlfile)));
      String line = null;
      while ((line = reader.readLine()) != null) {
         String[] files = line.split("\t", 2);
         renderImage(files[0], files[1]);
      }
      reader.close();
   }

   public static void renderImage(String svgFile, String targetFile) throws TranscoderException, IOException {
      PNGTranscoder t = new PNGTranscoder();
      TranscoderInput input = new TranscoderInput(svgFile);
      OutputStream out = new FileOutputStream(targetFile);
      TranscoderOutput output = new TranscoderOutput(out);
      t.transcode(input, output);

      out.flush();
      out.close();
   }
}

-- chris