Menu

1.2.0 Info.getImageWidth() returns null

2012-01-06
2013-04-30
  • Johan Mynhardt

    Johan Mynhardt - 2012-01-06

    Hi :)

    I've noticed that when the org.im4java.core.Info-object is initialized without the basic (new Info(source, true)) flag, a NumberFormatException is thrown when info.getImageWidth() is called.

    However, when I initialize the Info-object with the basic flag as true, it works as expected.

    Or is it just me? :P

     
  • Bernhard Bablok

    Bernhard Bablok - 2012-01-06

    Thanks for the hint, I consider this as a bug :-(

    In fact, when using the constructor with the basic-flag set to false the code will parse the output of "identify -verbose" and this output does not explicitly write image-width or image-height, but only image-geometry. So you could query the geometry with info.getImageGeometry(). Nevertheless my code should be intelligent enough to detect this situation and return the correct width and height.

    The update won't make it for version 1.2.1 (which will be deployed today), but I'll fix it in the next release.

    Bernhard

     
  • Johan Mynhardt

    Johan Mynhardt - 2012-01-13

    I basically did this afterwards, but there seem to be something funny going on.

    But then I ran into another problem, in that somehow it got the incorrect dimensions. But this seem only to be true for GIF files. I tried using both local and remote GIF animations as I thought it might the cause of a network issue somehow.

    I've tested with a PNG, SVG and GIF source, and only the GIF has this issue.

        @Test
        public void testDimensionVsParsedGeometryLocalGif() throws InfoException {
            Info infoOverlay = new Info(sourceTestGif, true);
            Info infoOverlay2 = new Info(sourceTestGif, false);
            Dimension dimensionOverlay = new Dimension(infoOverlay.getImageGeometry());
            Dimension dimensionOverlay2 = new Dimension(infoOverlay2.getImageGeometry());
            assertThat(dimensionOverlay, equalTo(dimensionOverlay2));
        }
    

    yields

    java.lang.AssertionError: 
    Expected: <Dimension{geometry='176x208+0+0', width=176, height=208}>
         got: <Dimension{geometry='122x158+0+0', width=122, height=158}>
    
     
  • Bernhard Bablok

    Bernhard Bablok - 2012-01-17

    It took me some time to figure this out, but I think the reason for this behavior is that your gif has more than one scene. The "identify -verbose" command outputs the geometry for every scene and the parser of the Info-class happily overwrites the attributes, therefore the complete-information will use the last geometry, whereas the basic-info will use the geometry of the first scene. You can test this hypothesis if you pass the scene-selector as part of the image, e.g. myimage.gif. Maybe you could also post the gif somewhere, since I currently can't reproduce the issue.

    I will have to change the implementation of the parser and internally maintain the attributes per scene.

    In fact, this brings up another bug: getImageWidth() and getImageHeight() currently return the width and height of the page, not of the image. Usually, but not always both are identical. I will fix this issue by additionally providing a getPageWidth() and getPageHeight() method.

    Bernhard

     
  • Johan Mynhardt

    Johan Mynhardt - 2012-01-18

    Aha! Your hypothesis is correct. Yesterday I created a utility class that I can use and during development I discovered that it uses the last frame/scene's dimensions, like you said.

     

Log in to post a comment.