code: public static int[] getImageSize(InputStream input) throws IOException
      {
          try {
              ImageInputStream imageInput = ImageIO.createImageInputStream(input);
              BufferedImage image = ImageIO.read(imageInput);
              return new int[]{image.getWidth(), image.getHeight()};
          } finally {
              input.close();
          }
      }
docs: Returns the size (width and height) of an image from the given input
  stream. This method closes the given stream.
  
  @param input the input stream with an image
  @return the size (width and height) of an image from the given input
  stream