Intervention/image · error · InvalidArgumentException

Unable to create media type from {identifier::class}

Error message

Unable to create media type from {identifier::class}

What it means

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

Source

Thrown at src/MediaType.php:61

    case IMAGE_X_ICON = 'image/x-icon';
    case IMAGE_VND_MICROSOFT_ICON = 'image/vnd.microsoft.icon';

    /**
     * Create media type from given identifier.
     *
     * @throws InvalidArgumentException
     */
    public static function create(string|self|Format|FileExtension $identifier): self
    {
        if ($identifier instanceof self) {
            return $identifier;
        }

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

        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 {

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Pass an identifier the MediaType factory understands: a media type string, Format/FileExtension enum, or file path
  2. Check the object's class is mappable to a known media type; arbitrary objects are not supported
  3. Convert the object to its media-type string (e.g. 'image/png') before calling

When it happens

Trigger: Thrown at src/MediaType.php:61 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/34df128775180031. Report an issue: GitHub.