xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Al Pacifico <pacif...@pobox.com>
Subject Inconsistent placement of transcoded image
Date Wed, 26 Jul 2017 05:44:51 GMT
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
545x803:fox-1295378.svg
191x455:cheetah-48433.svg
218x518:airplane-307246.svg
586x1497:automobile-295043.svg


I'm converting to PNG using the following code:

package com.example;

import java.io.*;
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
            ostream.flush();
            ostream.close();
        }
        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?
-Al

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

Mime
View raw message