Ctrl+K
v3.0.5

Configuration

Complete reference for all Imigi configuration options.

Tip
All configuration is passed as an object to Imigi.init(config). Every option is optional unless marked Required.

Basic Options

Top-level properties that control core editor behaviour.

OptionTypeDefaultDescription
selector Required string | HTMLElement CSS selector (e.g. '#editor') or DOM element where the editor mounts.
image string undefined URL or data URL of the image to load on initialization. Supports absolute URLs, relative paths, and base64 data URLs.
state string undefined JSON string of a previously saved editor state. Restores all objects, filters, and transformations. Takes precedence over image.
blankCanvasSize {width, height} undefined Creates a blank canvas with the given pixel dimensions instead of loading an image. Useful for creating graphics from scratch.
crossOrigin boolean false Sets crossOrigin="anonymous" on loaded images. Required for exporting cross-domain images. The server must send CORS headers.
watermarkText string undefined Text rendered as a watermark on export only (not visible while editing).
textureSize number 4096 Maximum WebGL texture size in pixels. Lower on weak devices to prevent memory issues. Common: 2048, 4096, 8192.
baseUrl string '' Base URL prepended to all asset paths (filters, stickers, frames). Set when assets live on a CDN or subdirectory.
saveUrl string undefined Endpoint that receives a POST with the exported image data (base64) when the user clicks Save.
activeLanguage string 'en' BCP 47 language code for the UI. See Translations for available languages.
Basic Options Example
const editor = await Imigi.init({
  selector: '#editor',
  image: 'https://example.com/photo.jpg',
  crossOrigin: true,
  watermarkText: 'Draft',
  textureSize: 4096,
  baseUrl: '/assets/imigi/',
  activeLanguage: 'en',
});

UI Configuration

The ui object controls the editor's user interface: display mode, theme, visibility, and default tool.

ui.visible boolean
Default: true
Whether the editor UI is visible on initialization. Set false to start hidden and show later with editor.open().
ui.mode 'inline' | 'overlay'
Default: 'inline'
inline renders inside its container in the document flow. overlay renders as a fullscreen modal on top of the page.
ui.forceOverlayModeOnMobile boolean
Default: true
Automatically switches to overlay mode on viewports narrower than 768px, regardless of ui.mode.
ui.allowEditorClose boolean
Default: true
Shows a close button in the editor header (overlay mode). Set false to prevent closing or handle it via your own UI.
ui.showExportPanel boolean
Default: false
When true, shows an export panel letting the user choose format (PNG, JPEG, JSON, SVG) and quality before saving. When false, save exports directly using tools.export defaults.
ui.defaultTool ToolName
Default: undefined
Tool to activate on open. Values: 'filter', 'finetune', 'crop', 'resize', 'draw', 'text', 'shapes', 'stickers', 'frame', 'fill', 'redact', 'decorate', 'corners', 'ai'.
ui.activeTheme 'light' | 'dark'
Default: 'light'
Active color theme. Ships with 'light' and 'dark'. Custom themes registered via ui.themes can also be referenced by name. See Theming.
ui.themes ImigiTheme[]
Default: built-in light & dark
Array of custom theme objects with name and variables (CSS variable map). Merged with built-in themes. See Theming.
UI Configuration Example
ui: {
  visible: true,
  mode: 'overlay',
  forceOverlayModeOnMobile: true,
  allowEditorClose: true,
  showExportPanel: true,
  defaultTool: 'crop',
  activeTheme: 'dark',
}

The ui.nav object controls the main tool navigation bar.

ui.nav.position 'top' | 'bottom' | 'left' | 'right'
Default: 'top'
Position of the tool nav. 'left'/'right' render a vertical sidebar nav. 'top'/'bottom' render a horizontal strip.
ui.nav.replaceDefault boolean
Default: false
When true, built-in nav items are replaced entirely by items. When false, custom items append after defaults.
ui.nav.items NavItem[]
Default: all built-in tools
Array of nav items. Each has: name (string), icon (SVG string or image URL), label (display text), action (tool name string or callback function).
Custom Navigation Example
ui: {
  nav: {
    position: 'left',
    replaceDefault: true,
    items: [
      { name: 'crop',   icon: 'crop-icon',   label: 'Crop',    action: 'crop' },
      { name: 'filter', icon: 'filter-icon', label: 'Filters', action: 'filter' },
      { name: 'draw',   icon: 'draw-icon',   label: 'Draw',    action: 'draw' },
      { name: 'text',   icon: 'text-icon',   label: 'Text',    action: 'text' },
      {
        name: 'custom',
        icon: '<svg ...>...</svg>',
        label: 'My Action',
        action: () => { console.log('Custom!'); }
      },
    ],
  },
}

The ui.menubar object controls the secondary toolbar (undo, redo, zoom, save).

ui.menubar.position 'top' | 'bottom' | ''
Default: 'bottom'
Position of the menubar. Empty string '' hides it entirely.
ui.menubar.items ToolbarItemConfig[]
Default: undo, redo, zoom, save
Array of toolbar items. Types: { type: 'button', icon, label, action }, { type: 'separator' }, { type: 'spacer' } (pushes right), { type: 'widget', element } (custom DOM).
Custom Menubar Example
ui: {
  menubar: {
    position: 'top',
    items: [
      { type: 'button', icon: 'undo',     label: 'Undo',     action: 'undo' },
      { type: 'button', icon: 'redo',     label: 'Redo',     action: 'redo' },
      { type: 'separator' },
      { type: 'button', icon: 'zoom-in',  label: 'Zoom In',  action: 'zoomIn' },
      { type: 'button', icon: 'zoom-out', label: 'Zoom Out', action: 'zoomOut' },
      { type: 'spacer' },
      { type: 'button', icon: 'save',     label: 'Save',     action: 'save' },
    ],
  },
}

Open Image Dialog

The ui.openImageDialog object configures the dialog shown when no image is preloaded.

ui.openImageDialog.show boolean
Default: true
Show the Open Image dialog when no image is provided. Set false to skip and show a blank canvas or wait for programmatic loading.
ui.openImageDialog.replaceDefaultSampleImages boolean
Default: false
When true, built-in sample images are replaced by sampleImages. When false, custom samples are appended.
ui.openImageDialog.sampleImages SampleImage[]
Default: built-in samples
Array of sample images for the dialog. Each has: url (full image URL), thumbnail (preview URL), label (display name).
Open Image Dialog Example
ui: {
  openImageDialog: {
    show: true,
    replaceDefaultSampleImages: true,
    sampleImages: [
      { url: '/samples/nature.jpg',   thumbnail: '/samples/nature-sm.jpg',   label: 'Nature' },
      { url: '/samples/portrait.jpg', thumbnail: '/samples/portrait-sm.jpg', label: 'Portrait' },
      { url: '/samples/city.jpg',     thumbnail: '/samples/city-sm.jpg',     label: 'City' },
    ],
  },
}

Color Presets

The ui.colorPresets object defines color swatches in color pickers throughout the editor.

ui.colorPresets.replaceDefault boolean
Default: false
When true, replaces built-in color presets entirely.
ui.colorPresets.items string[]
Default: built-in palette
Array of CSS color strings. Supports hex, rgb, rgba, and named colors.
Color Presets Example
ui: {
  colorPresets: {
    replaceDefault: true,
    items: [
      '#000000', '#ffffff', '#f44336', '#e91e63',
      '#9c27b0', '#3f51b5', '#2196f3', '#00bcd4',
      '#4caf50', '#ffeb3b', '#ff9800', '#795548',
      'rgba(0,0,0,0)', // transparent
    ],
  },
}

Tool Configuration

The tools object lets you configure every individual tool with presets, defaults, and constraints.

Filter Tool

Image filter presets (grayscale, sepia, vintage, etc.).

tools.filter.replaceDefault boolean
Default: false
Replace all built-in filters with the custom list.
tools.filter.items FilterItem[]
Default: built-in presets
Each item has: name (unique id), label (display name), matrix (20-element 4x5 color matrix array).

Finetune Tool

Fine-tuning sliders for image adjustments.

tools.finetune.replaceDefault boolean
Default: false
Replace default finetune items entirely.
tools.finetune.items string[]
Default: ['brightness','contrast','saturation','exposure','hue','vibrance','temperature']
Slider names to show. Order determines UI order. All sliders range -100 to 100, default 0.

Crop Tool

Aspect ratio presets and crop zone behaviour.

tools.crop.defaultRatio number | null
Default: null (free crop)
Default aspect ratio. Use 16/9, 1 (square), or null for free-form.
tools.crop.allowCustomRatio boolean
Default: true
Allow users to enter custom aspect ratios via width/height inputs. Set false to restrict to presets only.
tools.crop.replaceDefaultPresets boolean
Default: false
Replace built-in ratio presets with presets.
tools.crop.presets CropPreset[]
Default: Free, Original, Square, 16:9, 4:3, 3:2, 2:3
Each preset: { label: '16:9', ratio: 16/9 }. Use ratio: null for free crop.
tools.crop.cropZone object
Default: {}
showGuides (boolean, true) — rule-of-thirds grid. showDimensions (boolean, true) — pixel dimensions on crop zone.

Resize Tool

Image resize constraints.

OptionTypeDefaultDescription
tools.resize.minWidthnumber1Minimum width in px.
tools.resize.maxWidthnumber10000Maximum width in px.
tools.resize.minHeightnumber1Minimum height in px.
tools.resize.maxHeightnumber10000Maximum height in px.

Draw Tool

Freehand drawing brushes and settings.

tools.draw.replaceDefaultBrushSizes boolean
Default: false
Replace default brush size presets.
tools.draw.brushSizes number[]
Default: [2, 5, 10, 20, 40]
Brush size options in pixels.
tools.draw.replaceDefaultBrushTypes boolean
Default: false
Replace default brush types.
tools.draw.brushTypes string[]
Default: ['pencil','marker','highlighter','eraser']
Available brush types.

Text Tool

Text tool fonts, defaults, and presets.

tools.text.replaceDefaultItems boolean
Default: false
Replace built-in font list.
tools.text.defaultText string
Default: 'Your text here'
Placeholder text for new text objects.
tools.text.controlsPadding number
Default: 10
Padding (px) between text bounding box and control handles.
tools.text.items TextFontItem[]
Default: built-in fonts
Each item: { family: 'Arial', label: 'Arial', url: '...' }. The url is optional, for loading web fonts (e.g. Google Fonts CSS URL).
Text Tool with Custom Fonts
tools: {
  text: {
    replaceDefaultItems: true,
    defaultText: 'Type something...',
    items: [
      { family: 'Inter',       label: 'Inter',    url: 'https://fonts.googleapis.com/css2?family=Inter' },
      { family: 'Playfair Display', label: 'Playfair', url: 'https://fonts.googleapis.com/css2?family=Playfair+Display' },
      { family: 'Arial',       label: 'Arial' },
      { family: 'Georgia',     label: 'Georgia' },
    ],
  },
}

Shapes Tool

Geometric shapes available in the shapes tool.

tools.shapes.replaceDefault boolean
Default: false
Replace all built-in shapes.
tools.shapes.items ShapeItem[]
Default: rectangle, circle, triangle, line, polygon, arrow, star
Each item: { name, label, icon, svgPath }. The svgPath is optional for custom shapes.

Stickers Tool

Sticker categories and images.

tools.stickers.replaceDefault boolean
Default: false
Replace all built-in sticker categories.
tools.stickers.items StickerCategory[]
Default: built-in categories
Each category: { name, label, icon, items: [{ url, label }] }.
Custom Stickers Example
tools: {
  stickers: {
    replaceDefault: true,
    items: [
      {
        name: 'brand-logos',
        label: 'Brand Logos',
        icon: '<svg ...>...</svg>',
        items: [
          { url: '/stickers/logo-dark.svg',  label: 'Dark Logo' },
          { url: '/stickers/logo-light.svg', label: 'Light Logo' },
        ],
      },
      {
        name: 'badges',
        label: 'Badges',
        icon: '<svg ...>...</svg>',
        items: [
          { url: '/stickers/sale.png' },
          { url: '/stickers/new.png' },
        ],
      },
    ],
  },
}

Frame Tool

Decorative frames applied around the image.

tools.frame.replaceDefault boolean
Default: false
Replace built-in frame presets.
tools.frame.items FrameItem[]
Default: built-in frames
Each item: { name, label, thumbnail, images: { top, right, bottom, left, corner } }.

Fill Tool

Canvas background fill defaults.

tools.fill.defaultMode 'solid' | 'image' | 'gradient'
Default: 'solid'
Default fill mode when the tool opens.
tools.fill.defaultColor string
Default: '#ffffff'
Default solid fill color.
tools.fill.defaultImageUrl string
Default: undefined
Default background image URL for image fill mode.
tools.fill.defaultImageFitMode 'cover' | 'contain' | 'stretch'
Default: 'cover'
'cover' fills canvas (may crop). 'contain' fits within (may letterbox). 'stretch' distorts to fill.
tools.fill.defaultGradient GradientConfig
Default: linear, white to black
Object with type ('linear'|'radial'), angle (degrees, linear only), and stops array of { offset: number, color: string }.

Redact Tool

Censoring tool for hiding sensitive areas.

tools.redact.defaultMode 'blur' | 'pixelate' | 'solid'
Default: 'blur'
Default redaction method.
tools.redact.defaultShape 'rect' | 'ellipse' | 'brush'
Default: 'rect'
Default shape for redaction areas. 'brush' allows freehand.
tools.redact.defaultSolidColor string
Default: '#000000'
Fill color for 'solid' mode.
tools.redact.defaultBlurAmount number
Default: 20
Blur radius in px for 'blur' mode. Range: 1–100.
tools.redact.defaultPixelateAmount number
Default: 10
Pixel block size for 'pixelate' mode. Range: 2–50.
tools.redact.defaultBrushWidth number
Default: 30
Freehand brush width in px when shape is 'brush'.

Decorate Tool

Decoration overlay tool for custom images on the canvas.

tools.decorate.maxUploadSizeBytes number
Default: 5242880 (5 MB)
Max file size for uploaded decorations.
tools.decorate.maxUploadWidth number
Default: 4096
Max pixel width for uploads.
tools.decorate.maxUploadHeight number
Default: 4096
Max pixel height for uploads.
tools.decorate.allowedExtensions string[]
Default: ['png','jpg','jpeg','svg','webp']
Allowed file extensions for uploads.
tools.decorate.enableUpload boolean
Default: true
Show the upload button.
tools.decorate.enableDragDrop boolean
Default: true
Allow drag-and-drop of images onto the canvas.
tools.decorate.dragDropTarget string | HTMLElement
Default: editor container
CSS selector or DOM element as the drop target.
tools.decorate.presets DecoratePreset[]
Default: []
Preset decorations: { url, thumbnail, label }.
tools.decorate.defaultOpacity number
Default: 1
Default opacity (0 transparent, 1 opaque).
tools.decorate.defaultSizePct number
Default: 25
Default size as % of canvas width.
tools.decorate.defaultRotation number
Default: 0
Default rotation angle in degrees.

Import Tool

File import behaviour, allowed types, and size limits.

tools.import.validImgExtensions string[]
Default: ['png','jpg','jpeg','webp','svg','gif','bmp']
Accepted file extensions for the file dialog and drag-and-drop.
tools.import.maxFileSize number
Default: 10485760 (10 MB)
Maximum import file size in bytes.
tools.import.fitOverlayToScreen boolean
Default: true
Scale imported overlays to fit the visible canvas. false uses original dimensions.
tools.import.openDroppedImageAsBackground boolean
Default: false
When true, dropped images replace the background instead of being added as overlays.

Export Tool

Default export format, quality, and filename.

OptionTypeDefaultDescription
tools.export.defaultFormat'png'|'jpeg'|'json'|'svg''png'Output format. 'json' exports state for restoration.
tools.export.defaultQualitynumber0.92JPEG quality (0–1). Ignored for PNG.
tools.export.defaultNamestring'image'Filename (without extension) for download.

Zoom Tool

Canvas zoom behaviour.

tools.zoom.allowUserZoom boolean
Default: true
Allow zoom via mouse wheel and pinch gestures. false locks zoom.
tools.zoom.fitImageToScreen boolean
Default: true
Auto-scale image to fit the canvas on load. false uses native pixel dimensions.
tools.zoom.zoomMode 'pointer' | 'center'
Default: 'pointer'
'pointer' zooms towards cursor position. 'center' zooms towards canvas center.

Object Defaults

The objectDefaults object sets default properties for newly created objects. Supports global, shape, sticker, and text scopes.

Inheritance
Per-type defaults are merged on top of global. A property on objectDefaults.text overrides the same property on objectDefaults.global for text objects.

objectDefaults.global

PropertyTypeDefaultDescription
fillstring'#000000'Default fill color.
strokestring''Default stroke color. Empty = no stroke.
erasablebooleantrueCan be erased with eraser brush.
widthnumber200Default width (px).
heightnumber200Default height (px).

objectDefaults.shape

PropertyTypeDefaultDescription
fillstring'#2196f3'Shape fill color.
strokestring''Shape border color.
erasablebooleantrueCan be erased.
widthnumber200Default width.
heightnumber200Default height.

objectDefaults.sticker

PropertyTypeDefaultDescription
erasablebooleantrueCan be erased.
widthnumber150Default width.
heightnumber150Default height.

objectDefaults.text

PropertyTypeDefaultDescription
fillstring'#000000'Text color.
textAlign'left'|'center'|'right''left'Horizontal alignment.
underlinebooleanfalseUnderlined by default.
linethroughbooleanfalseStrikethrough by default.
fontStyle'normal'|'italic''normal'Font style.
fontFamilystring'Arial'Font family.
fontSizenumber24Font size (px).
fontWeightstring|number'normal'Weight: 'normal', 'bold', or 100–900.
strokestring''Text outline color.
erasablebooleantrueCan be erased.
Object Defaults Example
objectDefaults: {
  global: {
    fill: '#333333',
    erasable: false,
  },
  shape: {
    fill: 'rgba(33,150,243,0.5)',
    stroke: '#1976d2',
    width: 300,
    height: 200,
  },
  sticker: { width: 100, height: 100 },
  text: {
    fill: '#ffffff',
    fontFamily: 'Inter',
    fontSize: 32,
    fontWeight: 'bold',
    textAlign: 'center',
  },
}

Object Controls

The objectControls object determines which interactive handles appear on selected objects. Supports global, shape, sticker, and text scopes.

Careful
Hiding too many controls can confuse users. Consider your use case before disabling handles.
PropertyTypeDefaultDescription
hideTopLeftbooleanfalseHide top-left resize handle.
hideTopRightbooleanfalseHide top-right resize handle.
hideBottomRightbooleanfalseHide bottom-right resize handle.
hideBottomLeftbooleanfalseHide bottom-left resize handle.
hideRotatingPointbooleanfalseHide rotation handle.
hideFloatingControlsbooleanfalseHide floating toolbar (delete, duplicate).
unlockAspectRatiobooleanfalseAllow free resize without preserving aspect ratio.
lockMovementbooleanfalsePrevent dragging. Can still resize/rotate.
Object Controls Example
objectControls: {
  global: {
    hideRotatingPoint: false,
    hideFloatingControls: false,
  },
  shape: { unlockAspectRatio: true },
  sticker: {
    hideTopLeft: true,
    hideTopRight: true,
    hideBottomLeft: true,
  },
  text: {
    lockMovement: true,
    hideRotatingPoint: true,
  },
}

Callbacks

Callback functions invoked at key lifecycle moments. Passed at the top level of the config object.

onLoad (editor: ImigiInstance) => void
Called after full initialization when the UI is ready.
onSave (data: ExportData, editor: ImigiInstance) => void
Called on Save. data contains dataUrl, blob, state, format, quality.
onClose (editor: ImigiInstance) => void | boolean
Called when editor closes. Return false to prevent closing.
onOpen (editor: ImigiInstance) => void
Called when the editor is opened.
onFileOpen (file: File, editor: ImigiInstance) => void
Called when a file is opened via dialog or drag-and-drop.
onMainImageLoaded (image: HTMLImageElement, editor: ImigiInstance) => void
Called after the background image finishes loading and renders on canvas.
Callbacks Example
const editor = await Imigi.init({
  selector: '#editor',
  image: '/photos/sample.jpg',

  onLoad(editor) {
    console.log('Editor ready!');
  },

  onSave(data, editor) {
    // Upload exported image
    fetch('/api/upload', {
      method: 'POST',
      body: JSON.stringify({ image: data.dataUrl, format: data.format }),
      headers: { 'Content-Type': 'application/json' },
    });
  },

  onClose(editor) {
    if (editor.isDirty()) {
      return confirm('You have unsaved changes. Close anyway?');
    }
  },

  onOpen(editor) {
    console.log('Editor opened');
  },

  onFileOpen(file, editor) {
    console.log('Opened:', file.name, file.size);
  },

  onMainImageLoaded(image, editor) {
    console.log('Image:', image.naturalWidth, 'x', image.naturalHeight);
  },
});

AI Configuration

The ai object configures AI-powered features (generative fill, background removal, smart selection).

Security
Never expose your API token in client-side production code. Use ai.proxyUrl to route requests through your backend where the token is stored securely.
ai.replicateApiToken string
Default: undefined
Replicate API token for direct calls. Only for local dev or SSR. In production use proxyUrl.
ai.proxyUrl string
Default: undefined
Backend proxy URL. Imigi sends AI requests here; your server forwards to Replicate with the token attached server-side.
AI - Development
// Dev only - never use tokens in production client code
ai: {
  replicateApiToken: 'r8_YOUR_DEV_TOKEN_HERE',
}
AI - Production
// Production - proxy through your backend
ai: {
  proxyUrl: 'https://api.yoursite.com/imigi-ai-proxy',
}

Complete Example

A comprehensive configuration demonstrating all major option groups together.

Full Configuration Example
import Imigi from 'imigi';

const editor = await Imigi.init({

  // ---- Basic Options ----
  selector: '#image-editor',
  image: '/photos/landscape.jpg',
  crossOrigin: true,
  baseUrl: '/assets/imigi/',
  activeLanguage: 'en',
  textureSize: 4096,

  // ---- UI ----
  ui: {
    mode: 'overlay',
    activeTheme: 'dark',
    allowEditorClose: true,
    showExportPanel: true,
    defaultTool: 'crop',
    nav: { position: 'left' },
    menubar: {
      position: 'top',
      items: [
        { type: 'button', icon: 'undo', label: 'Undo', action: 'undo' },
        { type: 'button', icon: 'redo', label: 'Redo', action: 'redo' },
        { type: 'spacer' },
        { type: 'button', icon: 'save', label: 'Save', action: 'save' },
      ],
    },
    colorPresets: {
      replaceDefault: true,
      items: ['#000', '#fff', '#f44336', '#2196f3', '#4caf50', '#ff9800'],
    },
  },

  // ---- Tools ----
  tools: {
    crop: {
      defaultRatio: 16 / 9,
      allowCustomRatio: true,
    },
    resize: { maxWidth: 4000, maxHeight: 4000 },
    draw: { brushSizes: [2, 5, 10, 25, 50] },
    text: {
      defaultText: 'Add your text',
      items: [
        { family: 'Inter',    label: 'Inter' },
        { family: 'Georgia',  label: 'Georgia' },
        { family: 'Courier New', label: 'Courier' },
      ],
    },
    fill: {
      defaultMode: 'solid',
      defaultColor: '#f5f5f5',
    },
    redact: {
      defaultMode: 'blur',
      defaultBlurAmount: 25,
    },
    export: {
      defaultFormat: 'jpeg',
      defaultQuality: 0.85,
      defaultName: 'edited-photo',
    },
    zoom: {
      allowUserZoom: true,
      fitImageToScreen: true,
    },
    import: {
      maxFileSize: 10485760,
      openDroppedImageAsBackground: false,
    },
  },

  // ---- Object Defaults ----
  objectDefaults: {
    text: {
      fill: '#ffffff',
      fontFamily: 'Inter',
      fontSize: 28,
    },
    shape: {
      fill: 'rgba(33,150,243,0.4)',
      stroke: '#1976d2',
    },
  },

  // ---- Object Controls ----
  objectControls: {
    sticker: { unlockAspectRatio: false },
  },

  // ---- AI ----
  ai: {
    proxyUrl: 'https://api.yoursite.com/imigi-ai',
  },

  // ---- Callbacks ----
  onLoad(editor) {
    console.log('Imigi ready');
  },
  onSave(data) {
    fetch('/api/images', {
      method: 'POST',
      body: JSON.stringify({ image: data.dataUrl }),
      headers: { 'Content-Type': 'application/json' },
    });
  },
  onClose(editor) {
    if (editor.isDirty()) {
      return confirm('Discard unsaved changes?');
    }
  },
});