Gets image dimensions for given file

@param imgFileName image file
@return dimensions of image
@throws IOException if the file is not a known image
15971
public ImageHeuristics getImageSizes(String imgFileName) throws
      IOException
  {
    int pos = imgFileName.lastIndexOf(".");
    if (pos == -1)
    {
      throw new IOException("No extension for file: " + imgFileName);
    }

    String suffix = imgFileName.substring(pos + 1);
    File tempFile = null;
    if ("svg".compareToIgnoreCase(suffix) == 0)
    {
      tempFile = getImageFile(ocf, imgFileName);
      if (tempFile != null)
      {
          long tempFileLength = tempFile.length();
          if (ocf.getClass() == OCFZipPackage.class)
          {
              tempFile.delete();
          }
        return new ImageHeuristics(0, 0, tempFileLength);
      }
      return null;
    }
    
    // Determine format by file extension and by inspecting the file
    tempFile = getImageFile(ocf, imgFileName);
    String formatFromInputStream = null;
    String formatFromSuffix = null;
    ImageInputStream imageInputStream = ImageIO.createImageInputStream(tempFile);
    Iterator<ImageReader> imageReaderIteratorFromInputStream = ImageIO.getImageReaders(imageInputStream);
    while (imageReaderIteratorFromInputStream.hasNext()) {
      ImageReader imageReaderFromInputStream = imageReaderIteratorFromInputStream.next();
      formatFromInputStream = imageReaderFromInputStream.getFormatName();
        
      Iterator<ImageReader> imageReaderIteratorFromSuffix = ImageIO.getImageReadersBySuffix(suffix);
        while (imageReaderIteratorFromSuffix.hasNext()) {
          ImageReader reader = imageReaderIteratorFromSuffix.next();
          formatFromSuffix = reader.getFormatName();
          
          if (formatFromSuffix != null && formatFromSuffix.equals(formatFromInputStream)) break;
        }
        if (formatFromSuffix != null && formatFromSuffix.equals(formatFromInputStream)) break;
    }
    imageInputStream.close();



      if (formatFromSuffix != null && formatFromSuffix.equals(formatFromInputStream)) {
      // file format and file extension matches; read image file
      
      try {
        BufferedImage image = ImageIO.read(tempFile);
        if (image == null) {
          report.message(MessageId.PKG_021, EPUBLocation.create(imgFileName));
          return null;
          
        } else {
          int width          = image.getWidth();
          int height         = image.getHeight();
          return new ImageHeuristics(width, height, tempFile.length());
        }
      }
      catch (IOException e)
      {
        report.message(MessageId.PKG_021, EPUBLocation.create(imgFileName));
        return null;
      }
      catch (RuntimeException argex)
      {
        report.message(MessageId.PKG_021, EPUBLocation.create(imgFileName));
        return null;
      }
      finally
      {
          if (ocf.getClass() == OCFZipPackage.class)
          {
              tempFile.delete();
          }
      }
  
    } else
      {
          if (ocf.getClass() == OCFZipPackage.class)
          {
              tempFile.delete();
          }
          if (formatFromSuffix != null) {
              // file format and file extension differs

              report.message(MessageId.PKG_022, EPUBLocation.create(imgFileName), formatFromInputStream, suffix);
              return null;

          } else {
              // file format could not be determined

              throw new IOException("Not a known image file: " + imgFileName);
          }
      }
  }
1098394
public static HashMap<String, Integer> getImageInfo(ImageInputStream input) {
        HashMap<String, Integer> map = new HashMap<String, Integer>(2);

        BufferedImage buff = null;
        try {
            buff = ImageIO.read(input);
            map.put("width", buff.getWidth());
            map.put("height", buff.getHeight());
            return map;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
645462
public static BufferedImage getImage(byte[] imageBytes) throws IOException {

		BufferedImage image = null;

		if (imageBytes != null) {
			ByteArrayInputStream stream = new ByteArrayInputStream(imageBytes);
			image = ImageIO.read(stream);
			stream.close();
		}

		return image;
	}
827243
public String read(String filename) throws IOException {
    Path p = new Path(filename);
    int size = (int) getMfs().getFileStatus(p).getLen();
    FSDataInputStream is = getMfs().open(p);
    byte[] content = new byte[size];
    is.readFully(content);
    return new String(content);
  }
867388
function getImageSizeFromFile(file) {
	return new Promise((resolve, reject) => {
		const isDataUrl = file.match(/^data:.+?;base64,/);

		if (isDataUrl) {
			// NB should use sync version of `sizeOf()` for buffers
			try {
				const data = Buffer.from(file.slice(isDataUrl[0].length), 'base64');
				return resolve(sizeForFileName('', sizeOf(data)));
			} catch (err) {
				return reject(err);
			}
		}

		sizeOf(file, (err, size) => {
			if (err) {
				reject(err);
			} else {
				resolve(sizeForFileName(path.basename(file), size));
			}
		});
	});
}
125149
public static String findMimeType( File imgFile ) {

		String result;
		String name = imgFile.getName().toLowerCase();
		if( name.endsWith( ".jpg" ) || name.endsWith( ".jpeg" ))
			result = MIME_JPG;
		else if( name.endsWith( ".gif" ))
			result = MIME_GIF;
		else if( name.endsWith( ".png" ))
			result = MIME_PNG;
		else if( name.endsWith( ".svg" ))
			result = MIME_SVG;
		else
			result = MIME_BINARY;

		return result;
	}
11977
def _get_image_size(self, image_path):
        """"""
        command = 'du -b %s' % image_path
        (rc, output) = zvmutils.execute(command)
        if rc:
            msg = ("Error happened when executing command du -b with"
                   "reason: %s" % output)
            LOG.error(msg)
            raise exception.SDKImageOperationError(rs=8)
        size = output.split()[0]
        return size
633951
function size($filename)
    {
        if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
            return false;
        }

        $filename = $this->_realpath($filename);
        if ($filename === false) {
            return false;
        }

        return $this->_size($filename);
    }
297343
public static Long getSize(final File file){
        if ( file!=null && file.exists() ){
            return file.length();
        }
        return null;
    }
1115374
public static String getImageFileFormat(File imageFile) {
        String imageFileName = imageFile.getName();
        String imageFormat = imageFileName.substring(imageFileName.lastIndexOf('.') + 1);
        if (imageFormat.matches("(pbm|pgm|ppm)")) {
            imageFormat = "pnm";
        } else if (imageFormat.matches("(jp2|j2k|jpf|jpx|jpm)")) {
            imageFormat = "jpeg2000";
        }
        return imageFormat;
    }
521990
public static int[] shrinkImage(BufferedImage srcImg, String dest, int width, int height) throws IOException {
		int w = srcImg.getWidth(null);
		int h = srcImg.getHeight(null);

		if (w <= width && h <= height) {
			width = w;
			height = h;
		} else {
			double r1 = (double) width / (double) w;
			double r2 = (double) height / (double) h;

			if (r1 > r2) {
				width = (int) (w * r2);
				height = (int) (h * r2);
			} else {
				width = (int) (w * r1);
				height = (int) (h * r1);
			}

			if (width <= 0)
				width = 1;
			if (height <= 0)
				height = 1;
		}

		int size = resizeImage(srcImg, dest, width, height);
		return new int[] { width, height, size };
	}
195208
def extract_image_size(self):
        '''
        
        '''
        width, _ = self._extract_alternative_fields(
            ['Image ImageWidth', 'EXIF ExifImageWidth'], -1, int)
        height, _ = self._extract_alternative_fields(
            ['Image ImageLength', 'EXIF ExifImageLength'], -1, int)
        return width, height
614664
public String getSize(String imgName) {

        String ret = (String)m_sizes.get(imgName);
        if (ret == null) {
            return "";
        }
        return ret;
    }
517086
public static function get_dimensions_for_size( $img_size ) {
		$width  = absint( $img_size['resize'][0] );
		$height = isset( $img_size['resize'][1] ) ? absint( $img_size['resize'][1] ) : 0;

		return array( $width, $height );
	}
146240
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();
        }
    }
1333850
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;
    }
314856
public static void encode2ImgFile(int width, int high, String imgFilename, String verifyCode) throws IOException{
        width = width < 1 ? defaultWidth : width;
        high = high < 1 ? defaultHigh : high;
        File outputFile = new File(imgFilename);
        File dir = outputFile.getParentFile();
        if(!dir.exists()){
            dir.mkdirs();
        }
        outputFile.createNewFile();
        FileOutputStream fos = new FileOutputStream(outputFile);
        outputImage(width, high, fos, verifyCode);
        fos.close();
    }