Method to validate whether the given mime is an image file

@param mime the mime type
@return boolean returns true if the file is image
332598
private boolean isImageType(String mime) {
		if (StringUtils.hasText(mime)) {
			for (String imageMime : IMAGE_MIMES) {
				if (mime.equalsIgnoreCase(imageMime)) {
					return true;
				}
			}
		}
		return false;
	}
582340
public function mimeToExt($mime, $incl_dot = true, $ret_typeid = false)
	{
		$this->debug->groupCollapsed(__METHOD__, $mime);
		$ext = '';
		// map to image_type
		$type = isset($this->imageTypes[$mime])
			? $this->imageTypes[$mime]
			: null;
		if ($type) {
			if ($incl_dot) {
				$ext = '.';
			}
			$ext .= image_type_to_extension($type);
			if ($ret_typeid) {
				$ext = $type;
			}
		} else {
			$this->debug->warn('unknown mime type');
		}
		$this->debug->groupEnd();
		return $ext;
	}
111363
public function isImage()
	{
		$mime = $this->getMimeType();
		
		// The $imageMimes property contains an array of file extensions and
		// their associated MIME types. We will loop through them and look for 
		// the MIME type of the current SymfonyUploadedFile.
		foreach ($this->imageMimes as $imageMime)
		{
			if (in_array($mime, (array) $imageMime))
			{
				return true;
			}
		}

		return false;
	}
193093
public static function isGifFile($filename)
    {
        try {
            $image = new ImageFile($filename);
            if (strtolower($image->getMime()) !== @image_type_to_mime_type(IMAGETYPE_GIF)) {
                return false;
            }

            return true;
        } catch (\RuntimeException $ex) {
            return false;
        }
    }
726934
private static boolean isImage(String hexString) {
    	boolean isImage = false;
    	//png
    	if (hexString.startsWith("89504e470d0a1a0a")) {    		
    		isImage = true;
    	//gif	
    	} else if (hexString.startsWith("474946383761") || hexString.startsWith("474946383961")) {    		
    		isImage = true;
    	// jpeg	
    	} else if (hexString.startsWith("ffd8ffe0")) {    		
    		isImage = true;
    	}
    	return isImage;    	
    }
1058222
@Pure
	public static boolean isShapeFile(URL file) {
		return FileType.isContentType(
				file,
				MimeName.MIME_SHAPE_FILE.getMimeConstant());
	}
1330101
public function is_valid_image() {
        $mimetype = $this->get_mimetype();
        if (!file_mimetype_in_typegroup($mimetype, 'web_image')) {
            return false;
        }
        if (!$info = $this->get_imageinfo()) {
            return false;
        }
        if ($info['mimetype'] !== $mimetype) {
            return false;
        }
        // ok, GD likes this image
        return true;
    }
739757
public function mime()
    {
        if (!$this->exists()) {
            return false;
        }
        if (function_exists('finfo_open')) {
            $finfo = finfo_open(FILEINFO_MIME);
            $finfo = finfo_file($finfo, $this->pwd());
            if (!$finfo) {
                return false;
            }
            list($type) = explode(';', $finfo);

            return $type;
        }
        if (function_exists('mime_content_type')) {
            return mime_content_type($this->pwd());
        }

        return false;
    }
1283711
private function validMimeImage($extension, $mimes)
    {
        if (is_array($mimes)) {
            foreach ($mimes as $mime) {
                if (!strstr($mime, 'image/')) {
                    throw new \InvalidArgumentException(htmlspecialchars(
                        "The extension $extension is not an image extension."
                    ));
                }
            }
        } else {
            if (!strstr($mimes, 'image/')) {
                throw new \InvalidArgumentException(htmlspecialchars(
                    "The extension $extension is not an image extension."
                ));
            }
        }
    }
1241374
public static function isPngFile($filename)
    {
        try {
            $image = new ImageFile($filename);
            if (strtolower($image->getMime()) !== @image_type_to_mime_type(IMAGETYPE_PNG)) {
                return false;
            }

            return true;
        } catch (\RuntimeException $ex) {
            return false;
        }
    }
966254
public static function isImage($mimeType)
    {
        if (in_array($mimeType, self::$mimeTypes, true)) {
            return (bool)preg_match('|^image/.+$|', $mimeType);
        }

        return false;
    }
626764
public function mime($mime = null)
    {
        if (!func_num_args()) {
            list($mime, $charset) = $this->_inspectContentType();
            return $this->_mime = $mime;
        }

        $this->_mime = $mime ? strtolower($mime) : null;
        $this->_updateContentType();
        return $this;
    }
1094827
def is_image(file):
    
    match = re.match(r'\.(png|jpe?g)', _get_extension(file), re.IGNORECASE)
    if match:
        return True
    else:
        return isinstance(resolve_bot_file_id(file), types.Photo)
1076660
public static function isImage($image)
	{
		if (!trim($image))
		{
			return false;
		}

		$dot = strrpos($image, '.') + 1;

		$ext = substr($image, $dot);
		$ext = strtolower($ext);
		if (!in_array($ext, array('gif', 'jpg', 'jpe', 'jpeg', 'png', 'bmp')))
		{
			return false;
		}

		return true;
	}
102278
public boolean mediaIsImage() {
        String contentType = this.getContentType();
        return contentType != null && this.media != null && contentType.startsWith("image") && !contentType.equals("image/gif");
    }
903096
protected function validateExtensionAndMimeType()
    {
        if ($this->allowed_file_extensions == null && ($this->file_extensions_mime_types == null || empty($this->file_extensions_mime_types))) {
            // it is not set to limit uploaded file extensions and mime types.
            return true;
        }

        // get only file extension of uploaded file.
        $file_name_explode = explode('.', $this->files[$this->input_file_name]['name']);
        if (!is_array($file_name_explode)) {
            unset($file_name_explode);
            $this->setErrorMessage(
                sprintf(static::__('Unable to validate extension for the file %s.'), $this->files[$this->input_file_name]['name']),
                'RDU_UNABLE_VALIDATE_EXT',
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['size'],
                $this->files[$this->input_file_name]['type']
            );
            return false;
        }
        $file_extension = strtolower($file_name_explode[count($file_name_explode)-1]);
        unset($file_name_explode);

        // validate allowed extensions.
        if (is_array($this->allowed_file_extensions) && !in_array($file_extension, $this->allowed_file_extensions)) {
            unset($file_extension);
            $this->setErrorMessage(
                sprintf(static::__('You have uploaded the file that is not allowed extension. (%s)'), $this->files[$this->input_file_name]['name']),
                'RDU_NOT_ALLOW_EXT',
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['size'],
                $this->files[$this->input_file_name]['type']
            );
            return false;
        }

        // validate allowed mime types that match uploaded file's extension.
        if (is_array($this->file_extensions_mime_types) && !empty($this->file_extensions_mime_types)) {
            if (!array_key_exists($file_extension, $this->file_extensions_mime_types)) {
                unset($file_extension);
                $this->setErrorMessage(
                    sprintf(static::__('Unable to validate the file extension and mime type. (%s). This file extension was not set in the &quot;file_extensions_mime_types&quot; property.'), $this->files[$this->input_file_name]['name']),
                    'RDU_UNABLE_VALIDATE_EXT_AND_MIME',
                    $this->files[$this->input_file_name]['name'],
                    $this->files[$this->input_file_name]['name'],
                    $this->files[$this->input_file_name]['size'],
                    $this->files[$this->input_file_name]['type']
                );
                return false;
            } else {
                $Finfo = new \finfo();
                $file_mimetype = $Finfo->file($this->files[$this->input_file_name]['tmp_name'], FILEINFO_MIME_TYPE);
                if (is_array($this->file_extensions_mime_types[$file_extension]) && !in_array(strtolower($file_mimetype), array_map('strtolower', $this->file_extensions_mime_types[$file_extension]))) {
                    unset($file_extension, $Finfo);
                    $this->setErrorMessage(
                        sprintf(static::__('The uploaded file has invalid mime type. (%s : %s).'), $this->files[$this->input_file_name]['name'], $file_mimetype),
                        'RDU_INVALID_MIME',
                        $this->files[$this->input_file_name]['name'] . ' : ' . $file_mimetype,
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $file_mimetype
                    );
                    unset($file_mimetype);
                    return false;
                } elseif (!is_array($this->file_extensions_mime_types[$file_extension])) {
                    unset($file_extension, $file_mimetype, $Finfo);
                    $this->setErrorMessage(
                        static::__('Unable to validate mime type. The format of &quot;file_extensions_mime_types&quot; property is incorrect.'),
                        'RDU_UNABLE_VALIDATE_MIME',
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                }
                unset($file_mimetype, $Finfo);
            }
        }

        unset($file_extension);
        return true;
    }
347121
private byte[] getImageContent(InputStream in, String mime) throws FMSException {
		byte[] imageInByte = null;
		ByteArrayOutputStream baos = null;
		try {
			BufferedImage originalImage = ImageIO.read(in);
			baos = new ByteArrayOutputStream();
			ImageIO.write(originalImage, mime, baos);
			baos.flush();
			imageInByte = baos.toByteArray();
			baos.close();
		} catch (IOException e) {
			throw new FMSException("Error while reading the upload file.", e);
		} finally {
			close(baos);
			close(in);
		}
		return imageInByte;
	}