Ctrl+K
v3.0.5

Tools Guide

Comprehensive guide to all 15+ editing tools available in Imigi. Each tool can be individually enabled, configured, and controlled programmatically through the editor API.

Enabling Tools

By default, all tools are enabled. You can specify which tools to include via the tools array in your configuration. Only the tools listed in the array will appear in the editor toolbar.

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  // Only include these tools in the toolbar
  tools: ['filter', 'finetune', 'crop', 'resize', 'draw', 'text', 'shapes']
});

Filter Tool

The Filter tool applies visual effects to the entire image. Imigi ships with a rich set of built-in filters and supports adding custom filters. Filters are non-destructive and can be removed at any time before the final export.

Built-in Filters

The following filters are available out of the box:

Configuration

OptionTypeDefaultDescription
tools.filter.itemsstring[]All built-in filtersArray of filter names to display. Use this to limit which filters the user sees.
tools.filter.replaceDefaultbooleanfalseWhen true, the items array completely replaces the default filters instead of appending.

API Methods

MethodParametersReturnsDescription
tools.filter.apply(name)name: stringvoidApplies the specified filter to the image.
tools.filter.remove(name)name: stringvoidRemoves the specified filter from the image.
tools.filter.getAll()string[]Returns an array of all currently applied filter names.
tools.filter.isApplied(name)name: stringbooleanChecks whether a specific filter is currently applied.
tools.filter.addCustom(config)config: FilterConfigvoidRegisters a new custom filter that users can apply.

Example: Applying Filters Programmatically

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    filter: {
      // Only show these filters
      items: ['grayscale', 'sepia', 'vintage', 'blur', 'sharpen'],
      replaceDefault: true
    }
  }
});

// Apply a filter
editor.tools.filter.apply('sepia');

// Check if a filter is applied
if (editor.tools.filter.isApplied('sepia')) {
  console.log('Sepia is active');
}

// Remove a filter
editor.tools.filter.remove('sepia');

// List all active filters
const active = editor.tools.filter.getAll();
console.log('Active filters:', active);

Example: Adding a Custom Filter

JavaScript
// Register a custom "Sunset" filter
editor.tools.filter.addCustom({
  name: 'sunset',
  label: 'Sunset Glow',
  preview: '/filters/sunset-thumb.jpg',
  apply(canvas) {
    canvas.applyColorMatrix([
      1.2, 0.1, 0.0, 0, 10,
      0.0, 1.0, 0.1, 0, 5,
      0.0, 0.0, 0.8, 0, -10,
      0,   0,   0,   1, 0
    ]);
  }
});
Tip

Filters are stacked in the order they are applied. Applying grayscale followed by sepia produces a different result than sepia followed by grayscale. Use getAll() to inspect the current stack order.

Finetune Tool (Adjustments)

The Finetune tool provides granular control over the image's visual properties. Each adjustment is a numeric slider that the user can drag, or you can set programmatically. All adjustments are non-destructive and are applied in real time.

Available Adjustments

AdjustmentRangeDefaultDescription
brightness-100 to 1000Controls overall lightness or darkness of the image.
contrast-100 to 1000Increases or decreases the difference between light and dark areas.
saturation-100 to 1000Controls color intensity. -100 produces grayscale.
exposure-100 to 1000Simulates camera exposure compensation.
hue-180 to 1800Rotates all colors around the color wheel by the specified degrees.
vibrance-100 to 1000Boosts muted colors without oversaturating already vivid ones.
temperature-100 to 1000Shifts the color temperature. Positive values are warmer (yellow), negative values are cooler (blue).

Configuration

OptionTypeDefaultDescription
tools.finetune.defaultsobject{}An object mapping adjustment names to their initial values, e.g. { brightness: 10, contrast: 5 }.

API Methods

MethodParametersReturnsDescription
tools.finetune.set(name, value)name: string, value: numbervoidSets a specific adjustment to the given value.
tools.finetune.get(name)name: stringnumberReturns the current value of the specified adjustment.
tools.finetune.reset(name?)name?: stringvoidResets the specified adjustment (or all adjustments if no name is given) to their default values.
tools.finetune.getAll()objectReturns an object with all current adjustment values.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    finetune: {
      // Start with slightly boosted brightness and contrast
      defaults: {
        brightness: 10,
        contrast: 15,
        saturation: 5
      }
    }
  }
});

// Adjust brightness programmatically
editor.tools.finetune.set('brightness', 25);
editor.tools.finetune.set('temperature', -20);

// Read current values
const brightness = editor.tools.finetune.get('brightness'); // 25
const allValues = editor.tools.finetune.getAll();
console.log(allValues);
// { brightness: 25, contrast: 15, saturation: 5, exposure: 0, hue: 0, vibrance: 0, temperature: -20 }

// Reset only brightness
editor.tools.finetune.reset('brightness');

// Reset all adjustments
editor.tools.finetune.reset();
Tip

Use vibrance instead of saturation for portrait photos. Vibrance boosts muted colors while protecting already saturated skin tones from becoming unnatural.

Crop Tool

The Crop tool allows users to select a rectangular region of the image to keep, discarding everything outside the selection. Imigi provides several preset aspect ratios and supports fully custom ratios and freeform cropping.

Preset Ratios

Configuration

OptionTypeDefaultDescription
tools.crop.defaultRatiostring | nullnull (free)The initial crop ratio when the tool opens. Set to '1:1', '16:9', etc.
tools.crop.allowCustomRatiobooleantrueWhether the user can enter a custom width:height ratio.
tools.crop.presetsstring[]All built-in ratiosArray of ratio strings to show. E.g. ['1:1', '16:9', 'free'].
tools.crop.cropzoneobjectnullInitial cropzone coordinates: { x, y, width, height } in pixels.

API Methods

MethodParametersReturnsDescription
tools.crop.apply()voidApplies the current crop selection and removes the cropped-out area.
tools.crop.drawZone(config){ x, y, width, height }voidProgrammatically draws a crop zone at the specified coordinates.
tools.crop.resetCropzone()voidResets the crop zone back to the full image area.
tools.crop.setRatio(ratio)ratio: stringvoidSets the crop zone to a specific aspect ratio (e.g. '16:9').

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    crop: {
      defaultRatio: '16:9',
      allowCustomRatio: false,
      presets: ['1:1', '4:3', '16:9', 'free']
    }
  }
});

// Draw a crop zone programmatically
editor.tools.crop.drawZone({
  x: 50,
  y: 50,
  width: 400,
  height: 300
});

// Apply the crop
editor.tools.crop.apply();

// Or reset to start over
editor.tools.crop.resetCropzone();
Tip

When building a profile picture editor, set defaultRatio to '1:1' and presets to ['1:1'] to lock the user into a square crop. Combine with resize to enforce final dimensions.

Resize Tool

The Resize tool changes the overall dimensions of the image. It supports constrained resizing (maintaining the original aspect ratio) and unconstrained resizing. You can set minimum and maximum constraints to prevent users from producing images that are too large or too small.

Configuration

OptionTypeDefaultDescription
tools.resize.minWidthnumber1Minimum allowed width in pixels.
tools.resize.maxWidthnumber10000Maximum allowed width in pixels.
tools.resize.minHeightnumber1Minimum allowed height in pixels.
tools.resize.maxHeightnumber10000Maximum allowed height in pixels.
tools.resize.lockAspectRatiobooleantrueWhether the aspect ratio is locked by default.

API Methods

MethodParametersReturnsDescription
tools.resize.resize(w, h)w: number, h: numbervoidResizes the image to the specified width and height.
tools.resize.getSize(){ width, height }Returns the current image dimensions.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    resize: {
      minWidth: 100,
      maxWidth: 2000,
      minHeight: 100,
      maxHeight: 2000,
      lockAspectRatio: true
    }
  }
});

// Get the current size
const size = editor.tools.resize.getSize();
console.log(`Current size: ${size.width}x${size.height}`);

// Resize to 800x600
editor.tools.resize.resize(800, 600);
Tip

For social media image editors, combine the resize tool with crop presets to enforce platform-specific dimensions. For example, Instagram posts (1080x1080), Twitter banners (1500x500), or Facebook covers (820x312).

Draw Tool

The Draw tool enables freehand drawing directly on the canvas. Users can select from multiple brush types, sizes, and colors. Each drawn stroke is added as a separate canvas object that can be individually selected, moved, resized, or deleted.

Brush Types

Configuration

OptionTypeDefaultDescription
tools.draw.brushSizesnumber[][2, 5, 10, 20, 40]Array of brush size options (in pixels) presented to the user.
tools.draw.brushTypesstring[]All built-in typesArray of brush type names to display.
tools.draw.replaceDefaultBrushSizesbooleanfalseWhen true, brushSizes replaces defaults instead of appending.
tools.draw.replaceDefaultBrushTypesbooleanfalseWhen true, brushTypes replaces defaults instead of appending.
tools.draw.defaultColorstring'#000000'Default brush color.
tools.draw.defaultSizenumber5Default brush size in pixels.
tools.draw.defaultTypestring'pencil'Default brush type.

API Methods

MethodParametersReturnsDescription
tools.draw.enable()voidActivates drawing mode on the canvas.
tools.draw.disable()voidDeactivates drawing mode.
tools.draw.setBrushType(type)type: stringvoidSets the active brush type.
tools.draw.setBrushSize(size)size: numbervoidSets the active brush size in pixels.
tools.draw.setBrushColor(color)color: stringvoidSets the active brush color (hex, rgb, or named color).
tools.draw.getBrushType()stringReturns the current brush type name.
tools.draw.getBrushSize()numberReturns the current brush size.
tools.draw.getBrushColor()stringReturns the current brush color.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    draw: {
      brushSizes: [1, 3, 8, 15, 30],
      brushTypes: ['pencil', 'marker', 'highlighter'],
      replaceDefaultBrushTypes: true,
      defaultColor: '#ff0000',
      defaultSize: 3,
      defaultType: 'pencil'
    }
  }
});

// Enable drawing mode
editor.tools.draw.enable();

// Switch to marker with blue color
editor.tools.draw.setBrushType('marker');
editor.tools.draw.setBrushColor('#3498db');
editor.tools.draw.setBrushSize(15);

// Read current brush settings
console.log(editor.tools.draw.getBrushType());  // 'marker'
console.log(editor.tools.draw.getBrushColor()); // '#3498db'
console.log(editor.tools.draw.getBrushSize());  // 15

// Disable drawing mode when done
editor.tools.draw.disable();
Tip

Each drawn stroke becomes its own Fabric.js object. Users can switch out of drawing mode to select, move, scale, or delete individual strokes. Use the highlighter brush type for annotation workflows where the underlying content must remain visible.

Text Tool

The Text tool lets users add fully editable text to the canvas. Each text element supports full typographic control including font family, size, color, weight, style, decoration, and alignment. Text objects can be repositioned, resized, and rotated on the canvas.

Typography Options

Configuration

OptionTypeDefaultDescription
tools.text.defaultTextstring'Your text here'The placeholder text when a new text element is added.
tools.text.itemsobject[]Built-in fontsArray of font objects: { fontFamily, url? }. Use url for custom web fonts.
tools.text.controlsPaddingnumber10Padding in pixels around the text bounding box controls.
tools.text.defaultFontSizenumber24Default font size for new text elements.
tools.text.defaultColorstring'#000000'Default text color.

API Methods

MethodParametersReturnsDescription
tools.text.add(options?)options?: TextOptionsFabricObjectAdds a new text element to the canvas. Returns the created Fabric.js object.
tools.text.selectOrAddText()FabricObjectIf a text object is already selected, enters edit mode on it. Otherwise, adds a new text element.

Example: Adding Custom Fonts

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    text: {
      defaultText: 'Type something...',
      defaultFontSize: 32,
      defaultColor: '#ffffff',
      items: [
        { fontFamily: 'Arial' },
        { fontFamily: 'Georgia' },
        { fontFamily: 'Courier New' },
        // Custom Google Fonts
        {
          fontFamily: 'Lobster',
          url: 'https://fonts.googleapis.com/css2?family=Lobster'
        },
        {
          fontFamily: 'Pacifico',
          url: 'https://fonts.googleapis.com/css2?family=Pacifico'
        },
        // Custom self-hosted font
        {
          fontFamily: 'BrandFont',
          url: '/fonts/brand-font.woff2'
        }
      ]
    }
  }
});

// Add text programmatically
editor.tools.text.add({
  text: 'Hello World!',
  fontFamily: 'Lobster',
  fontSize: 48,
  fill: '#e74c3c',
  fontWeight: 'bold',
  textAlign: 'center',
  left: 200,
  top: 100
});

// Add another text element and enter edit mode immediately
editor.tools.text.selectOrAddText();
Tip

When using custom web fonts, ensure the font file is loaded before calling tools.text.add(). Imigi automatically loads Google Fonts URLs specified in the items config, but self-hosted fonts should be preloaded via CSS @font-face or the Font Loading API for best results.

Shapes Tool

The Shapes tool adds geometric shapes to the canvas. Each shape is a fully interactive Fabric.js object that can be moved, resized, rotated, and styled (fill color, stroke color, stroke width, opacity).

Built-in Shapes

Configuration

OptionTypeDefaultDescription
tools.shapes.itemsstring[]All built-in shapesArray of shape names to display. E.g. ['rectangle', 'circle', 'arrow'].
tools.shapes.replaceDefaultbooleanfalseWhen true, items replaces the default set instead of appending.
tools.shapes.defaultFillstring'transparent'Default fill color for new shapes.
tools.shapes.defaultStrokestring'#000000'Default stroke (border) color.
tools.shapes.defaultStrokeWidthnumber2Default stroke width in pixels.

API Methods

MethodParametersReturnsDescription
tools.shape.add(type, options?)type: string, options?: ShapeOptionsFabricObjectAdds a shape of the specified type to the canvas. Returns the Fabric.js object.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    shapes: {
      items: ['rectangle', 'circle', 'triangle', 'arrow', 'star'],
      replaceDefault: true,
      defaultFill: 'rgba(52, 152, 219, 0.3)',
      defaultStroke: '#2980b9',
      defaultStrokeWidth: 3
    }
  }
});

// Add a red circle
editor.tools.shape.add('circle', {
  radius: 50,
  fill: 'rgba(231, 76, 60, 0.5)',
  stroke: '#c0392b',
  strokeWidth: 2,
  left: 150,
  top: 150
});

// Add a directional arrow
editor.tools.shape.add('arrow', {
  stroke: '#e67e22',
  strokeWidth: 4,
  left: 100,
  top: 200,
  width: 200,
  height: 0
});

// Add a 5-pointed star
editor.tools.shape.add('star', {
  points: 5,
  fill: '#f1c40f',
  stroke: '#f39c12',
  left: 300,
  top: 100
});
Tip

Use shapes with semi-transparent fills for annotations. Setting fill to rgba() values creates overlays that highlight areas of the image without completely obscuring them.

Stickers Tool

The Stickers tool lets users add image overlays from organized categories. Stickers are PNG or SVG images that are placed on the canvas as interactive objects. Imigi supports custom sticker packs organized into named categories with thumbnails.

Configuration

OptionTypeDefaultDescription
tools.stickers.itemsStickerCategory[][]Array of sticker category objects. Each category has a name, icon, and items array of sticker URLs.
tools.stickers.replaceDefaultbooleanfalseWhen true, items replaces the built-in sticker set.

API Methods

MethodParametersReturnsDescription
tools.stickers.add(url)url: stringFabricObjectAdds a sticker image from the given URL to the canvas.
tools.stickers.getCategories()StickerCategory[]Returns all available sticker categories.

Example: Custom Sticker Categories

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    stickers: {
      replaceDefault: true,
      items: [
        {
          name: 'Emojis',
          icon: '/stickers/emoji-icon.png',
          items: [
            '/stickers/emojis/smile.png',
            '/stickers/emojis/heart.png',
            '/stickers/emojis/thumbsup.png',
            '/stickers/emojis/star.png',
            '/stickers/emojis/fire.png'
          ]
        },
        {
          name: 'Badges',
          icon: '/stickers/badge-icon.png',
          items: [
            '/stickers/badges/verified.svg',
            '/stickers/badges/premium.svg',
            '/stickers/badges/new.svg'
          ]
        },
        {
          name: 'Brand Assets',
          icon: '/stickers/brand-icon.png',
          items: [
            '/stickers/brand/logo-dark.png',
            '/stickers/brand/logo-light.png',
            '/stickers/brand/watermark.png'
          ]
        }
      ]
    }
  }
});

// Add a sticker programmatically
editor.tools.stickers.add('/stickers/brand/watermark.png');
Tip

Use SVG stickers when possible -- they scale without quality loss. For branding workflows, create a "Watermark" category so users can quickly add brand assets to images.

Frame Tool

The Frame tool applies decorative borders and frames around the image. Frames can be simple solid borders, gradient borders, or complex image-based frames (such as Polaroid, filmstrip, or ornamental designs). Each frame is rendered as an overlay that wraps the image content.

Configuration

OptionTypeDefaultDescription
tools.frame.itemsFrameConfig[]Built-in framesArray of frame config objects: { name, label, preview, borderWidth?, borderColor?, imageUrl? }.
tools.frame.replaceDefaultbooleanfalseWhen true, items replaces the default frames instead of appending.

API Methods

MethodParametersReturnsDescription
tools.frame.apply(name)name: stringvoidApplies the specified frame to the image.
tools.frame.remove()voidRemoves the currently applied frame.
tools.frame.getApplied()string | nullReturns the name of the currently applied frame, or null.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    frame: {
      items: [
        {
          name: 'simple-white',
          label: 'White Border',
          preview: '/frames/white-thumb.jpg',
          borderWidth: 20,
          borderColor: '#ffffff'
        },
        {
          name: 'polaroid',
          label: 'Polaroid',
          preview: '/frames/polaroid-thumb.jpg',
          imageUrl: '/frames/polaroid-overlay.png'
        },
        {
          name: 'ornamental',
          label: 'Ornamental Gold',
          preview: '/frames/gold-thumb.jpg',
          imageUrl: '/frames/gold-overlay.png'
        }
      ]
    }
  }
});

// Apply a frame
editor.tools.frame.apply('polaroid');

// Check which frame is applied
console.log(editor.tools.frame.getApplied()); // 'polaroid'

// Remove the frame
editor.tools.frame.remove();
Tip

Image-based frames (imageUrl) should be transparent PNG files. The frame image is stretched or tiled around the edges of the canvas. Design the overlay with the center area fully transparent so the image content shows through.

Fill Tool

The Fill tool sets the canvas background. It supports three modes: solid color, image fill, and gradient. The fill appears behind all other canvas objects and the original image. This is particularly useful when the canvas has been expanded beyond the original image boundaries or for creating backgrounds for collage-style compositions.

Fill Modes

Configuration

OptionTypeDefaultDescription
tools.fill.defaultModestring'color'The initial fill mode: 'color', 'image', or 'gradient'.
tools.fill.defaultColorstring'#ffffff'Default solid color fill.
tools.fill.defaultImageUrlstringnullDefault background image URL.
tools.fill.defaultGradientobjectnullDefault gradient: { type: 'linear'|'radial', angle: number, stops: [{offset, color}] }.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    fill: {
      // Start with a gradient background
      defaultMode: 'gradient',
      defaultGradient: {
        type: 'linear',
        angle: 135,
        stops: [
          { offset: 0, color: '#667eea' },
          { offset: 1, color: '#764ba2' }
        ]
      }
    }
  }
});
Tip

The fill is especially useful in combination with rounded corners or when using Imigi as a social media post creator. Set a gradient fill, add text elements, and export as a complete social graphic.

Redact Tool

The Redact tool allows users to censor or obscure areas of the image. This is commonly used for hiding sensitive information such as faces, license plates, personal data, or private content. Imigi supports three redaction modes, each applied as a drawn rectangular or elliptical region.

Redaction Modes

Configuration

OptionTypeDefaultDescription
tools.redact.defaultModestring'blur'The default redaction mode: 'blur', 'pixelate', or 'solid'.
tools.redact.defaultShapestring'rectangle'The shape of the redaction area: 'rectangle' or 'ellipse'.
tools.redact.blurAmountnumber10Blur intensity (1-50). Higher values produce a stronger blur.
tools.redact.pixelateAmountnumber10Pixelation block size (1-50). Higher values produce larger mosaic blocks.
tools.redact.solidColorstring'#000000'The fill color used in 'solid' mode.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'document.jpg',
  tools: {
    redact: {
      defaultMode: 'pixelate',
      defaultShape: 'rectangle',
      pixelateAmount: 15,
      blurAmount: 20,
      solidColor: '#000000'
    }
  }
});
Tip

For GDPR compliance or document processing workflows, use the pixelate mode with a high block size to ensure sensitive text is completely unreadable. The blur mode at low values may still allow reconstruction of text via deblurring algorithms.

Decorate Tool (Assets)

The Decorate tool enables users to upload and add external image assets to the canvas. Unlike stickers (which are pre-configured), the Decorate tool allows direct file upload from the user's device. Uploaded images become interactive canvas objects that can be repositioned, resized, rotated, and layered. Preset assets can also be provided for quick access.

Configuration

OptionTypeDefaultDescription
tools.decorate.maxUploadSizeBytesnumber10485760 (10 MB)Maximum file size in bytes for uploaded images.
tools.decorate.allowedExtensionsstring[]['jpg', 'jpeg', 'png', 'svg', 'webp', 'gif']Allowed file extensions for upload.
tools.decorate.enableUploadbooleantrueWhether to show the file upload button.
tools.decorate.enableDragDropbooleantrueWhether to accept drag-and-drop file uploads.
tools.decorate.presetsAssetPreset[][]Array of preset asset objects: { label, url, thumbnail? }.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    decorate: {
      maxUploadSizeBytes: 5242880, // 5 MB
      allowedExtensions: ['png', 'svg', 'webp'],
      enableUpload: true,
      enableDragDrop: true,
      presets: [
        {
          label: 'Company Logo',
          url: '/assets/company-logo.png',
          thumbnail: '/assets/company-logo-thumb.png'
        },
        {
          label: 'Watermark',
          url: '/assets/watermark.png',
          thumbnail: '/assets/watermark-thumb.png'
        },
        {
          label: 'Signature',
          url: '/assets/signature.svg'
        }
      ]
    }
  }
});
Tip

Use the presets array to provide commonly used assets (logos, watermarks, badges) so users do not need to upload them every time. Combine with enableUpload: false to create a curated asset library without free uploads.

Corners Tool

The Corners tool applies rounded corners to the entire image. This is a simple but effective tool for softening the appearance of the final output, commonly used for avatar images, card designs, and thumbnail generation. The corner radius is adjustable via a slider.

Configuration

OptionTypeDefaultDescription
tools.corners.defaultRadiusnumber0Initial corner radius in pixels.
tools.corners.maxRadiusnumber200Maximum corner radius allowed.

API Methods

MethodParametersReturnsDescription
tools.corners.setRadius(r)r: numbervoidSets the corner radius in pixels.
tools.corners.getRadius()numberReturns the current corner radius.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'avatar.jpg',
  tools: {
    corners: {
      defaultRadius: 20,
      maxRadius: 150
    }
  }
});

// Set rounded corners programmatically
editor.tools.corners.setRadius(50);

// Make a fully circular crop (set radius to half the shortest dimension)
const size = editor.tools.resize.getSize();
const circleRadius = Math.min(size.width, size.height) / 2;
editor.tools.corners.setRadius(circleRadius);
Tip

To create a perfectly circular image, first crop to 1:1 ratio, then set the corner radius to half the image width. The exported PNG will include transparency in the corner areas.

AI Tool

The AI tool integrates AI-powered image processing features via the Replicate API. This enables advanced capabilities such as background removal, image upscaling, style transfer, object removal, and generative fill. AI features require an API token and process images through an external service.

Supported AI Features

Configuration

OptionTypeDefaultDescription
ai.replicateApiTokenstringnullYour Replicate API token. Required to enable AI features.
ai.proxyUrlstringnullOptional proxy URL to route API calls through your backend (recommended for production to avoid exposing your API token).
ai.featuresstring[]All featuresArray of AI feature names to enable.
ai.maxProcessingTimenumber60000Maximum time in ms to wait for AI processing before timing out.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  ai: {
    // Use a proxy in production to keep your token secure
    proxyUrl: 'https://your-api.example.com/replicate-proxy',
    features: ['background-removal', 'upscale', 'object-removal'],
    maxProcessingTime: 90000
  }
});

// For development/testing only (do NOT expose tokens in production)
const devEditor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  ai: {
    replicateApiToken: 'r8_your_dev_token_here'
  }
});
Tip

Never expose your Replicate API token in client-side code in production. Use the proxyUrl option to route all AI requests through your own backend, where the token is stored securely as an environment variable. The proxy endpoint simply forwards the request to Replicate with the token attached server-side.

Zoom Tool

The Zoom tool controls the canvas viewport zoom level. Users can zoom in to inspect fine details, zoom out to see the full image, or fit the image to the screen. Zoom is non-destructive and does not affect the exported image resolution.

Configuration

OptionTypeDefaultDescription
tools.zoom.allowUserZoombooleantrueWhether the user can zoom via scroll wheel or pinch gesture.
tools.zoom.fitImageToScreenbooleantrueWhether the image is automatically scaled to fit the editor viewport on load.
tools.zoom.zoomModestring'scroll'Zoom input mode: 'scroll' (mouse wheel), 'pinch' (touch), or 'both'.
tools.zoom.minLevelnumber0.1Minimum zoom level (0.1 = 10%).
tools.zoom.maxLevelnumber10Maximum zoom level (10 = 1000%).
tools.zoom.stepnumber0.1Zoom increment per scroll tick or button press.

API Methods

MethodParametersReturnsDescription
tools.zoom.zoom(level)level: numbervoidSets the zoom level (1 = 100%, 2 = 200%, etc.).
tools.zoom.fitToScreen()voidFits the entire image within the visible viewport.
tools.zoom.getLevel()numberReturns the current zoom level as a number.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  tools: {
    zoom: {
      allowUserZoom: true,
      fitImageToScreen: true,
      zoomMode: 'both',
      minLevel: 0.25,
      maxLevel: 5,
      step: 0.25
    }
  }
});

// Zoom to 200%
editor.tools.zoom.zoom(2);

// Get current zoom level
const level = editor.tools.zoom.getLevel();
console.log(`Current zoom: ${level * 100}%`); // "Current zoom: 200%"

// Fit to screen
editor.tools.zoom.fitToScreen();
Tip

Disable user zoom with allowUserZoom: false for simplified editing interfaces where zoom control is unnecessary, such as profile picture editors or quick crop tools. The image will still auto-fit to the viewport on load.

History (Undo/Redo)

Imigi includes a built-in undo/redo system that tracks every modification to the canvas. Each change (applying a filter, adding a shape, cropping, drawing a stroke, etc.) is recorded as a history entry. Users can step backward and forward through the history using toolbar buttons or keyboard shortcuts (Ctrl+Z / Ctrl+Shift+Z).

How It Works

Configuration

OptionTypeDefaultDescription
history.maxStepsnumber50Maximum number of history entries to keep. Older entries are discarded when the limit is reached.
history.enabledbooleantrueWhether undo/redo tracking is enabled.

API Methods

MethodParametersReturnsDescription
history.undo()voidUndoes the last action, restoring the previous state.
history.redo()voidRedoes the last undone action.
history.getHistory()HistoryEntry[]Returns the full history stack as an array of entries.
history.canUndo()booleanReturns true if there is an action that can be undone.
history.canRedo()booleanReturns true if there is an action that can be redone.
history.clear()voidClears all history entries. The current state becomes the only entry.

Example

JavaScript
const editor = await Imigi.init({
  selector: '#editor',
  image: 'photo.jpg',
  history: {
    maxSteps: 100
  }
});

// Make some changes
editor.tools.filter.apply('sepia');
editor.tools.finetune.set('brightness', 20);

// Undo the brightness change
editor.history.undo();

// Redo it
editor.history.redo();

// Check undo/redo availability (useful for disabling buttons)
const undoBtn = document.getElementById('undo-btn');
const redoBtn = document.getElementById('redo-btn');
undoBtn.disabled = !editor.history.canUndo();
redoBtn.disabled = !editor.history.canRedo();

// Inspect the history stack
const entries = editor.history.getHistory();
console.log(`${entries.length} history entries`);

// Clear all history
editor.history.clear();
Tip

Increase maxSteps for complex editing workflows where users need extensive undo capability. However, keep in mind that each history entry stores a canvas snapshot, so very large values may increase memory usage on large images. For most use cases, 50-100 steps is a good balance.