Inconsistent placement of transcoded image

Al Pacifico <[email protected]> Tue, 25 Jul 2017 22:44:51 -0700
Newsgroups gmane.text.xml.batik.user
Message-ID <CAGRVsLt-0L+OXjcTT5P7KFJtLXUxVhH7U9CvpzuYwyvc-8KUFw@mail.gmail.com>
--94eb2c07cc8e6d23ec055531f2e9
Content-Type: text/plain; charset="UTF-8"

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.

--94eb2c07cc8e6d23ec055531f2e9
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Sorry to ask so many questions, but I am experiencing inco=
nsistent placement of images within PNG&#39;s.<div><br></div><div>For examp=
le, I have four SVG&#39;s for which the height is far different than the wi=
dth (output of ImageMagick identify shown):</div><blockquote style=3D"margi=
n:0px 0px 0px 40px;border:none;padding:0px"><div><div>$ identify -format &#=
39;%hx%w:%f\n&#39; images/fox-1295378.svg images/cheetah-48433.svg images/a=
irplane-307246.svg images/automobile-295043.svg</div></div><div><div>545x80=
3:fox-1295378.svg</div></div><div><div>191x455:cheetah-48433.svg</div></div=
><div><div>218x518:airplane-307246.svg</div></div><div><div>586x1497:automo=
bile-295043.svg</div></div></blockquote><div><div><br></div><div>I&#39;m co=
nverting to PNG using the following code:</div><div><br></div><div><div>pac=
kage com.example;</div><div><br></div><div>import java.io.*;</div><div>impo=
rt java.nio.file.Paths;</div><div>import org.apache.batik.transcoder.image.=
PNGTranscoder;</div><div>import org.apache.batik.transcoder.SVGAbstractTran=
scoder;</div><div>import org.apache.batik.transcoder.TranscoderInput;</div>=
<div>import org.apache.batik.transcoder.TranscoderOutput;</div><div><br></d=
iv><div>public class Main {</div><div><br></div><div>=C2=A0 =C2=A0 public s=
tatic void main(String [] args) throws Exception {</div><div><br></div><div=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (args.length =3D=3D 2) {</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // read the input SVG document into Tran=
scoderInput</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 String svgU=
RI =3D Paths.get(args[0]).toUri().toString();</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 TranscoderInput input =3D new TranscoderInput(svgU=
RI);</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // define OutputSt=
ream to PNG Image and attach to TranscoderOutput</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 OutputStream ostream =3D new FileOutputStream(a=
rgs[1]);</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 TranscoderOutp=
ut output =3D new TranscoderOutput(ostream);</div><div>=C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 // create a JPEG transcoder</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 PNGTranscoder t =3D new PNGTranscoder();</div><=
div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // set the transcoding hints<=
/div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 t.addTranscodingHint(SV=
GAbstractTranscoder.KEY_HEIGHT, new Float(600));</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 t.addTranscodingHint(SVGAbstractTranscoder.KEY_=
WIDTH, new Float(600));</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 // convert and write output</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 t.transcode(input, output);</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 // flush and close the stream then exit</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ostream.flush();</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ostream.close();</div><div>=C2=A0 =C2=A0 =C2=A0=
 =C2=A0 }</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 else {</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.err.println(&quot;Usage: &lt;source =
file name&gt; &lt;destination file name&gt;&quot;);</div><div>=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 }</div><div>}</div></div><div><br>=
</div><div>The cheetah and fox images are centered vertically and horizonta=
lly on the PNG canvas, but the airplane and automobile images are centered =
horizontally, but appear at the top of the canvas.=C2=A0 Any ideas why?</di=
v><div>-Al</div><div><br></div>-- <br><div class=3D"gmail_signature">Please=
 forgive typo&#39;s, equally likely to have been typed on cell phone and to=
 have been typed one-handed.<div><br></div></div>
</div></div>

--94eb2c07cc8e6d23ec055531f2e9--