Get image type if it is one of: .gif, .jpg or .png

@param string $file Full path to file
@return string|boolean
13974
static public function type($file) {
        $type = getimagesize($file);
        $type = $type[2];
        switch($type) {
            case IMAGETYPE_GIF:     return 'gif';
            case IMAGETYPE_JPEG:    return 'jpg';
            case IMAGETYPE_PNG:     return 'png';
        }
        return FALSE;
    }
54826
final protected function getImageInfo($file)
    {
        $image = getimagesize($file);

        if ($image !== false) {
            return array(
                'width' => $image[0],
                'height' => $image[1],
                'type' => $image[2],
                'mime' => $image['mime'],
                'bits' => isset($image['bits']) ? $image['bits'] : null
            );
        } else {
            return false;
        }
    }
1206520
public function detectPath($file): string
    {
        if ($file == $this->noImage) {
            return Yii::getAlias($this->noImage);
        }

        $fullPath = $this->getImageSourcePath() . $file;

        if (is_file($fullPath)) {
            return $fullPath;
        }

        return false;
    }
1131743
public function filetype($file)
    {
        // for existing files, try to read the magic bytes
        if(file_exists($file) && is_readable($file) && filesize($file) > 5) {
            $fh = @fopen($file, 'rb');
            if(!$fh) return false;
            $magic = fread($fh, 5);
            fclose($fh);

            if(strpos($magic, "\x42\x5a") === 0) return Archive::COMPRESS_BZIP;
            if(strpos($magic, "\x1f\x8b") === 0) return Archive::COMPRESS_GZIP;
        }

        // otherwise rely on file name
        $file = strtolower($file);
        if (substr($file, -3) == '.gz' || substr($file, -4) == '.tgz') {
            return Archive::COMPRESS_GZIP;
        } elseif (substr($file, -4) == '.bz2' || substr($file, -4) == '.tbz') {
            return Archive::COMPRESS_BZIP;
        }

        return Archive::COMPRESS_NONE;
    }
1117070
private function getType(string $file): string
	{
		$css = '/\.(css|less)$/';
		$js = '/\.js$/';

		if (preg_match($css, $file)) {
			return self::CSS;
		} elseif (preg_match($js, $file)) {
			return self::JS;
		}
		throw new InvalidArgumentException("Unknown assets file '$file'");
	}
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)
189974
private function _getImageTypeFromFileName($imageFile)
    {
        $ext = strtolower((string)pathinfo($imageFile, PATHINFO_EXTENSION));

        if ('jpg' === $ext or 'jpeg' === $ext) {
            return ImageType::JPEG;
        } else if ('gif' === $ext) {
            return ImageType::GIF;
        } else if ('png' === $ext) {
            return ImageType::PNG;
        } else if ('wbm' === $ext or 'wbmp' === $ext) {
            return ImageType::WBMP;
        } else {
            return ImageType::UNKNOWN;
        }
    }
758459
public function get_mime($file){
        $type = $this->get_content_type($file);
        if( $type ){
            $type = array_map('trim', explode(';', $type));
            return $type[0];
        }else{
            return '';
        }
    }
1160855
public function get($file = "")
    {
        $support             = $this->support();
        list($code, $answer) = $this->generateCode();
        $image               = null;
        @session_start();
        $_SESSION['vitex.captcha.answer'] = strtolower($answer);
        if ($support == 'imagick') {
            $image = new \Imagick();
            $image->newImage($this->width, $this->height, "none");
            $image->setImageFormat('png');
            $image = $this->imagickLine($image, $this->linenum);
            $image = $this->imagickDrawText($image, $code);
            $image->swirlImage(30);
            $image->oilPaintImage(1);
            if ($file) {
                $image->writeImage($file);
            } else {
                header("Content-type:image/png");
                echo $image->getImageBlob();
            }
        } else {
            $image = imagecreate($this->width, $this->height);
            $color = imagecolorallocate($image, 255, 255, 255);
            imagecolortransparent($image, $color);
            $this->gdLine($image, $this->linenum);
            $this->gdDrawText($image, $code);
            if ($file) {
                imagepng($image, $file);
            } else {
                header("Content-type: image/jpeg; Cache-Control: no-store, no-cache, must-revalidate");
                imagepng($image);
            }
        }
    }
1141110
public function detectMimeType($file = null) {
		// Attempts to retrieve file info from FINFO
		// If FINFO functions are not available then try to retrieve MIME type from pre-defined MIMEs
		// If MIME type doesn't exist, then try (as a last resort) to use the (deprecated) mime_content_type function
		// If all else fails, just return application/octet-stream
		if (!function_exists('finfo_open')) {
			if (function_exists('mime_content_type')) {
				$type = mime_content_type($file);
				if (!empty($type)) {
					return $type;
				}
			}
			$extension = $this->_getExtension($file);
			$mimeType = $this->getMimeTypeByAlias($extension);
			if ($mimeType) {
				return $mimeType;
			}
			return 'application/octet-stream';
		}
		return $this->_detectMimeType($file);
	}
119324
protected function get_file( $file ) {

		$path_parts = $this->parse_path( $file );

		if ( '' === $path_parts[0] ) {
			$file = $this->root;
			unset( $path_parts[0] );
		} else {
			$file = $this->cwd;
		}

		foreach ( $path_parts as $part ) {

			if ( '' === $part ) {
				continue;
			}

			if ( 'dir' !== $file->type || false === isset( $file->contents->$part ) ) {
				return false;
			}

			$file = $file->contents->$part;
		}

		return $file;
	}
1367132
private function isAllowedFileType($file) {
	$path_parts = pathinfo($file);
	// if there is no extension AND no extension file are not allowed
	if(!isset($path_parts['extension']) && $this->config['security']['allowNoExtension'] == false) {
		return false;
	} else {
		return true;
	}
	$exts = array_map('strtolower', $this->config['security']['uploadRestrictions']);
	if($this->config['security']['uploadPolicy'] == 'DISALLOW_ALL') {
		if(!in_array(strtolower($path_parts['extension']), $exts))
			return false;
	}
	if($this->config['security']['uploadPolicy'] == 'ALLOW_ALL') {
		if(in_array(strtolower($path_parts['extension']), $exts))
			return false;
	}
	return true;
}
813466
public function setImageFromFile($file)
    {
        if (preg_match('/\.([^\.]+)$/', $file, $match) === 1) {
            $this->setMimeType('image/' . $match[1]);
        }
        return $this->setImageFromBlob(file_get_contents($file));
    }
727157
protected function getSize($file)
    {
        if (! file_exists($file)) {
            return [];
        }

        $info = pathinfo($file);
        $image = null;
        switch (strtolower($info['extension'])) {
            case 'gif':
                $image = imagecreatefromgif($file);
                break;
            case 'jpg':
            case 'jpeg':
                $image = imagecreatefromjpeg($file);
                break;
            case 'png':
                $image = imagecreatefrompng($file);
                break;
            default:
                break;
        }
        if ($image == null) {
            return [];
        } else {
            return [imagesx($image), imagesy($image)];
        }
    }
1060732
public static function getMimeType($file)
    {
        $mimeType = new MimeTypeGuesser();
        $extension = self::getExtension($file);

        return $mimeType->getTypeByExtension($file);
    }
552113
public function getMimeTypeFromFile($file)
	{
		$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
		if (array_key_exists($extension, $this->_alt_mime_types)) {
			return $this->_alt_mime_types[$extension];
		} else {
			return (new \Finfo(FILEINFO_MIME_TYPE))->file($file);
		}
	}
1324546
protected function encodeFile($file)
    {
        $type = pathinfo($file, PATHINFO_EXTENSION);

        $data = file_get_contents($file);

        if ($type == 'html') {
            return $data;
        }

        return 'data:image/'.$type.';base64,'.base64_encode($data);
    }