code: public static int getImageWidth(String imageLoc) {
  
          // Get the image as an InputStream
          InputStream is = null;
          try {
              URI imageUri = new URI(imageLoc);
              URL imageUrl = imageUri.toURL();
              is = imageUrl.openStream();
          } catch (Exception e) {
              jlogger.log(Level.SEVERE, "getImageWidth", e);
  
              return -1;
          }
          // Determine the image width
          try {
              // Create an image input stream on the image
              ImageInputStream iis = ImageIO.createImageInputStream(is);
  
              // Find all image readers that recognize the image format
              Iterator iter = ImageIO.getImageReaders(iis);
  
              // No readers found
              if (!iter.hasNext()) {
                  return -1;
              }
  
              // Use the first reader
              ImageReader reader = (ImageReader) iter.next();
              reader.setInput(iis, true);
              int width = reader.getWidth(0);
              iis.close();
  
              return width;
          } catch (IOException e) {
              jlogger.log(Level.SEVERE, "getImageWidth", e);
              // The image could not be read
          }
          return -1;
      }
docs: Determines the width of the first image in an image file in pixels.
  
  @param imageLoc
  the string location of the image (uri syntax expected)
  @return int the image width in pixels, or -1 if unable.
  @author Paul Daisey added 2011-05-13 to support WMTS ETS