AI Image Editor plugin
The AI Image Editor ships as a File Uploader plugin:
register it on <uc-config> and add ai-image-editor to the source list. The
plugin reads its settings (public key, CDN config, locale, and so on) straight
from the uploader config, so there’s nothing extra to wire up.
Note: The plugin needs @uploadcare/file-uploader ≥ 1.34.0 as a peer dependency
(it relies on uploaderApi.replaceFile). Use ≥ 1.35.1, since
Signed AI image generation is on by
default and that is the version whose authToken the plugin passes on. AI Image Editor is in public beta
and available on Pro, Business, and custom plans. On other plans its
requests fail with the
derivative_disabled error.
The plugin adds two things:
- Generate image is an upload source, shown because
ai-image-editoris insource-list. It opens the editor in generate mode, and the committed result is added as a new file (sourced toai-image-editor). - AI Edit is a file action on already-uploaded images. It opens the editor
in edit mode on that image, and the committed result replaces the original
entry in place (same list position; the entry gets a new
internalId) and keeps the original file’s name.
Configuration
The plugin consumes these <uc-config> keys (all standard uploader config,
set as attributes or properties). Keys are listed in their camelCase
property form; as HTML attributes they’re kebab-case (base-url,
cdn-cname, locale-name, …):
The plugin also adds config options of its own. useAiEditor toggles the file
action; the aiEditor* keys set the editor’s own options, so the editor the
plugin opens can be configured like a standalone one. They’re all optional. The
aiEditor* keys update an open editor live, and leaving one unset keeps the
editor’s default (aiEditorAspectRatios falls back to cropPreset first).
Use @uploadcare/ai-image-editor 0.2.9 or later for the aiEditor* keys.
As attributes they’re kebab-case:
aspectRatiosFromCropPreset(cropPreset) is exported from the plugin entry if
you want to derive the same ratios yourself.
React File Uploader
With the React File Uploader
(@uploadcare/react-uploader), pass the plugin in plugins and add
ai-image-editor to sourceList. The configuration keys above are props, the
plugin’s own aiEditor* keys included:
Note: Use @uploadcare/react-uploader ≥ 1.18.0. Earlier versions set
options the uploader doesn’t define itself as attributes, so an object option
such as aiEditorPresets reached the plugin as "[object Object]". 1.18.0 also
ships File Uploader 1.36.1, which covers the plugin’s peer dependency.
Importing the plugin also types these props (see Typed config).
Already-edited images
The AI Edit action hides itself for images that already carry CDN modifiers, for example ones edited with the built-in image editor. AI Edit operates on the original file and can’t carry those modifiers over, so offering it would silently drop the prior edits. The Generate image source is unaffected.
Typed config
Importing the plugin augments the uploader’s config type, so useAiEditor, the
aiEditor* keys (and the editor’s locale keys) are type-checked on <uc-config>, with no
casts needed.
If your project doesn’t pick the augmentation up automatically, reference the
plugin’s types once:
Beyond the uploader
The editor also works on its own, outside the File Uploader. See the AI Image Editor docs for the standalone component, its options, and the React wrapper.