Intervention/image · error · InvalidArgumentException

Unable to create media type from "{identifier}"

Error message

Unable to create media type from "{identifier}"

What it means

Error "Unable to create media type from "{identifier}"" thrown in Intervention/image.

Source

Thrown at src/MediaType.php:85

        if ($identifier instanceof FileExtension) {
            try {
                return $identifier->mediaType();
            } catch (NotSupportedException $e) {
                throw new InvalidArgumentException(
                    'Unable to create media type from "' . $identifier->value . '"',
                    previous: $e,
                );
            }
        }

        try {
            $type = self::from(strtolower($identifier));
        } catch (Error) {
            try {
                $type = FileExtension::from(strtolower($identifier))->mediaType();
            } catch (Error | NotSupportedException) {
                throw new InvalidArgumentException('Unable to create media type from "' . $identifier . '"');
            }
        }

        return $type;
    }

    /**
     * Try to create media type from given identifier and return null on failure.
     */
    public static function tryCreate(string|self|Format|FileExtension $identifier): ?self
    {
        try {
            return self::create($identifier);
        } catch (InvalidArgumentException) {
            return null;
        }
    }

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Pass a valid media type string such as "image/jpeg" or a file path with a known extension
  2. Check for typos in the media type (e.g. 'image/jpg' is not a registered media type, use 'image/jpeg')
  3. Use MediaType::tryFrom or the Format enum when the value is dynamic

When it happens

Trigger: Thrown at src/MediaType.php:85 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/2be9b45aaf61f4b5. Report an issue: GitHub.