Inconsistent placement of transcoded image

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Inconsistent placement of transcoded image

Al Pacifico
Sorry to ask so many questions, but I am experiencing inconsistent placement of images within PNG's.

For example, I have four SVG's for which the height is far different than the width (output of ImageMagick identify shown):
$ identify -format '%hx%w:%f\n' images/fox-1295378.svg images/cheetah-48433.svg images/airplane-307246.svg images/automobile-295043.svg

I'm converting to PNG using the following code:

package com.example;

import java.nio.file.Paths;
import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.batik.transcoder.SVGAbstractTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;

public class Main {

    public static void main(String [] args) throws Exception {

        if (args.length == 2) {
            // read the input SVG document into TranscoderInput
            String svgURI = Paths.get(args[0]).toUri().toString();
            TranscoderInput input = new TranscoderInput(svgURI);
            // define OutputStream to PNG Image and attach to TranscoderOutput
            OutputStream ostream = new FileOutputStream(args[1]);
            TranscoderOutput output = new TranscoderOutput(ostream);
            // create a JPEG transcoder
            PNGTranscoder t = new PNGTranscoder();
            // set the transcoding hints
            t.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, new Float(600));
            t.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, new Float(600));
            // convert and write output
            t.transcode(input, output);
            // flush and close the stream then exit
        else {
            System.err.println("Usage: <source file name> <destination file name>");

The cheetah and fox images are centered vertically and horizontally on the PNG canvas, but the airplane and automobile images are centered horizontally, but appear at the top of the canvas.  Any ideas why?

Please forgive typo's, equally likely to have been typed on cell phone and to have been typed one-handed.