Intervention/image · error · InvalidArgumentException

Unable to create media type from "{identifier->value}"

Error message

Unable to create media type from "{identifier->value}"

What it means

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

Source

Thrown at src/MediaType.php:72

            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 {
            $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;
    }

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Use a backed enum value that maps to a supported media type, e.g. Format::PNG->value
  2. Verify the media type string matches an entry like 'image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif', 'image/bmp', 'image/tiff', 'image/heic'
  3. Normalize casing and whitespace of the identifier before resolution

When it happens

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