Create an gd image according to the specified mime type

@param string $path image file
@param string $mime
@return gd image resource identifier
4196
protected function gdImageCreate($path,$mime){
		switch($mime){
			case 'image/jpeg':
			return imagecreatefromjpeg($path);

			case 'image/png':
			return imagecreatefrompng($path);

			case 'image/gif':
			return imagecreatefromgif($path);

			case 'image/xbm':
			return imagecreatefromxbm($path);
		}
		return false;
	}
485057
public static function mimetypeFile ($path)
		{
			$finfo = finfo_open(FILEINFO_MIME_TYPE);
			if ($finfo)
			{
				$info = finfo_file($finfo, $path);
				finfo_close($finfo);

				return $info;
			}

			return null;
		}
1117103
public static function createThumbnail($path, $width = 100, $height = 100, $resizeType = self::RESIZE_FILLED, $bgColor = 0xfff5ee)
    {
        $img = self::createFromFileByMime($path);

        // Build the thumbnail
        $new_img = imagecreatetruecolor($width, $height);

        if ($resizeType == self::RESIZE_FILLED) {
            // Fill the image gray
            if ( ! imagefilledrectangle($new_img, 0, 0, $width - 1, $height - 1, $bgColor)) {
                throw new \Exception('can`t create thumbnail: can`t fill new image by bg-color');
            }
        }

        // Resize and copy to the new image
        list(
            $src_x, $src_y, $src_w, $src_h,
            $dst_x, $dst_y, $dst_w, $dst_h
            )
            = self::calcResizeParams($resizeType, $img, $width, $height);
        if ( ! imagecopyresampled($new_img, $img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)) {
            throw new \Exception('can`t create thumbnail: can`t resize image');
        }

        return self::getJpegToVar($new_img);
    }
802519
public function initFromPath($path)
    {
        if ( ! file_exists($path)) {
            throw new \Hail\Image\Exception\NotReadableException(
                "Unable to find file ({$path})."
            );
        }

        // get mime type of file
        $mime = MimeType::getMimeTypeByFile($path);

        // define core
        switch (strtolower($mime)) {
            case 'image/png':
            case 'image/x-png':
                $core = @imagecreatefrompng($path);
                break;

            case 'image/jpg':
            case 'image/jpeg':
            case 'image/pjpeg':
                $core = @imagecreatefromjpeg($path);
                if (!$core) {
                    $core= @imagecreatefromstring(file_get_contents($path));
                }
                break;

            case 'image/gif':
                $core = @imagecreatefromgif($path);
                break;

            case 'image/webp':
            case 'image/x-webp':
                if ( ! function_exists('imagecreatefromwebp')) {
                    throw new \Hail\Image\Exception\NotReadableException(
                        "Unsupported image type. GD/PHP installation does not support WebP format."
                    );
                }
                $core = @imagecreatefromwebp($path);
                break;

            default:
                throw new \Hail\Image\Exception\NotReadableException(
                    "Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files."
                );
        }

        if (empty($core)) {
            throw new \Hail\Image\Exception\NotReadableException(
                "Unable to decode image from file ({$path})."
            );
        }

        $this->gdResourceToTruecolor($core);

        // build image
        $image = $this->initFromGdResource($core);
        $image->mime = $mime;
        $image->setFileInfoFromPath($path);

        return $image;
    }
572973
final public static function get_mimetype(
		string $fname, string $path_to_file=null
	) {

		if (null === $mime = self::_mime_extension($fname))
			return self::_mime_magic($fname, $path_to_file);
		return $mime;
	}
139012
public function save($path, $type = null)
    {
        #imagepng() - Output a PNG image to either the browser or a file
        #imagegif() - Output image to browser or file
        #imagewbmp() - Output image to browser or file
        #imagejpeg() - Output image to browser or file
        
        if (!$type) {
            $type = $this->type;
        }

        switch ($type) {
            case 'gif':
                imagegif($this->resource, $path);
                break;
            case 'png':
                $quality = (100 - $this->quality) / 10;

                if ($quality > 9) {
                    $quality = 9;
                }

                imagepng($this->resource, $path, $quality);
                break;
            case 'bmp':
            case 'wbmp':
                imagewbmp($this->resource, $path, $this->quality);
                break;
            case 'jpg':
            case 'jpeg':
            case 'pjpeg':
            default:
                imagejpeg($this->resource, $path, $this->quality);
                break;

        }

        return $this;
    }
64169
public function fileMimeType($path)
    {
        $type = $this->mimeDetect->findType(strtolower(pathinfo($path, PATHINFO_EXTENSION)));
        if (!empty($type)) {
            return $type;
        }

        return 'unknown/type';
    }
980373
public function create($path, array $data)
    {
        $data = array_merge($data, ['path' => $path]);

        return File::create($data);
    }
906867
public function getMimeType($path)
    {
        $mimeTypes = [
            'png'  => 'image/png',
            'jpe'  => 'image/jpeg',
            'jpeg' => 'image/jpeg',
            'jpg'  => 'image/jpeg',
            'gif'  => 'image/gif',
            'bmp'  => 'image/bmp',
            'ico'  => 'image/vnd.microsoft.icon',
            'tiff' => 'image/tiff',
            'tif'  => 'image/tiff',
            'svg'  => 'image/svg+xml',
            'svgz' => 'image/svg+xml',
        ];

        $ext = pathinfo($path, PATHINFO_EXTENSION);
        if (array_key_exists($ext, $mimeTypes)) {
            return $mimeTypes[$ext];
        }

        return null;
    }
71973
protected function canCreateTmb($path, $stat) {
		return $this->tmbPathWritable 
			&& strpos($path, $this->tmbPath) === false // do not create thumnbnail for thumnbnail
			&& $this->imgLib 
			&& strpos($stat['mime'], 'image') === 0 
			&& ($this->imgLib == 'gd' ? $stat['mime'] == 'image/jpeg' || $stat['mime'] == 'image/png' || $stat['mime'] == 'image/gif' : true);
	}
352353
private function loadFromPath(string $path): self
    {
        switch ($this->extension) {
            case self::FORMAT_JPEG:
                $this->createFromJpeg($path);
                break;
            case self::FORMAT_PNG:
                $this->createFromPng($path);
                break;
            case self::FORMAT_GIF:
                $this->createFromGif($path);
                break;
            case self::FORMAT_WD_IMAGE:
                $this->createFromEncrypted($path);
                break;
            default:
                throw new ImageException('This image format is not supported!');
        }
        return $this;
    }
523713
public function write($path, $string, $mimeType = null)
    {
        return $this->getFile($path)->write($string, $mimeType);
    }
401264
public function createPathHeader($name, $path = null)
    {
        $header = new Swift_Mime_Headers_PathHeader($name, $this->emailValidator);
        if (isset($path)) {
            $header->setFieldBodyModel($path);
        }
        $this->setHeaderCharset($header);

        return $header;
    }
1314925
private static function getMimeTypeOfFile($path)
    {
        $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime     = finfo_file($fileInfo, $path);
        finfo_close($fileInfo);

        return $mime;
    }
1100918
public static function get($path, array $info = null)
    {
        $info = $info ?: self::getSize($path);

        switch ($info['mime']) {
            case self::TYPE_JPG:
                $srcImg = imagecreatefromjpeg($path);
                break;
            case self::TYPE_PNG:
                $srcImg = imagecreatefrompng($path);
                break;
            case self::TYPE_GIF:
                $srcImg = imagecreatefromgif($path);
                break;
            case self::TYPE_BMP:
                $srcImg = imagecreatefromwbmp($path);
                break;
            case self::TYPE_WEBP:
                $srcImg = imagecreatefromwebp($path);
                break;
            default:
                throw new FileInvalidTypeException('Not supported image type.');
        }

        return $srcImg;
    }
1353966
def mimetype_from_path(path):
    
    extension = file_extension(path)
    if extension is not None:
        extension = extension.lower()
        if extension in gc.MIMETYPE_MAP:
            return gc.MIMETYPE_MAP[extension]
    return None
300526
static function make( $mime, $param = null, $paramValue = null ) {
		if ( null === $param || null === $paramValue ) {
			return $mime;
		}
		return "$mime;$param=$paramValue";
	}