Skip to content

Component API

VuePictureCropper is a thin Vue wrapper around Cropper.js and supports the full Cropper.js API.

This document only covers the component’s extended props and methods. For more advanced behavior, use the cropper instance with the Cropper.js API.

Usage examples

The component is simple but its options are numerous; it’s best to check the Examples and their source comments for usage.

Props

The component’s prop types are also the argument types for the useCropper composable.

OptionDescription
boxStyleStyles for the crop area container (the parent element that wraps Cropper)
imgImage URL used for cropping
optionsSee Cropper.js API
eventsSee Cropper.js API
presetModeSee Preset mode

TIP

Remote images involve CORS. The server must be configured accordingly; prefer local images to avoid issues.

  • Type declarations
ts
import type { CSSProperties } from 'vue'

export interface VuePictureCropperProps {
  /**
   * URL of the image to be cropped
   */
  img: string

  /**
   * Styles for the crop box container
   */
  boxStyle?: CSSProperties

  /**
   * Cropper.js options; see Cropper.js documentation
   */
  options?: CropperInstance.Options

  /**
   * Preset mode; see [Preset mode](./preset-mode.md)
   */
  presetMode?: PresetModeOptions
}

Common methods

The component adds several convenience methods on top of Cropper.js. Use the cropper instance to call these and other plugin APIs.

  • Type declarations
ts
export interface CropperInstance extends Cropper {
  /**
   * Get the cropped result as Base64
   *
   * Suitable for local preview
   */
  getDataURL: (options?: CropperInstance.GetCroppedCanvasOptions) => string

  /**
   * Get the cropped result as Blob
   *
   * Suitable for sending to the server
   */
  getBlob: (
    options?: CropperInstance.GetCroppedCanvasOptions,
  ) => Promise<Blob | null>

  /**
   * Get the cropped result as File
   *
   * Suitable for sending to the server
   *
   * @since 0.2.0
   */
  getFile: (
    options?: CropperInstance.GetCroppedCanvasOptions,
  ) => Promise<File | null>
}

Notes

All three are built-in plugin methods. Output format follows the source image format. They only work with local images, not remote ones.

Cropper.js also provides two common methods you can call on the instance:

  • Clear crop box: clear()
  • Reset crop box: reset()
  • Parameter options

All three extended methods accept the same options to control the output.

PropertyTypeDescriptionDefault
widthnumberWidth of the cropped resultSize of the cropped region on the source image
heightnumberHeight of the cropped resultSize of the cropped region on the source image
minWidthnumberMinimum width of the cropped result0
minHeightnumberMinimum height of the cropped result0
maxWidthnumberMaximum width of the cropped resultInfinity
maxHeightnumberMaximum height of the cropped resultInfinity
fillColorstringBackground color of the result (e.g. for PNG transparent areas)transparent
imageSmoothingEnabledbooleanWhether to smooth the cropped imagetrue
imageSmoothingQualitystringSmoothing quality: low / medium / highlow
fileNamestringFile name; only used by getFile. Optional.cropped-${timestamp}.${source extension}

To change output format or work with remote images, use Cropper.js’s getCroppedCanvas.

Released under the MIT License.