Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified

Image Editor

ImageEditor is a block component which enables basic image editing functionality such as:

  • cropping, resizing
  • rotating,
  • changing aspect ratio
  • flipping
  • resetting to original state

It requires a media object to work properly. You can also pass a site ID to which the edited image belongs to.

Props

siteId

TypeNumber
RequiredNo
Defaultselected site

Id of a site the edited image belongs to.

media

TypeObject
RequiredYes

This object needs to contain at least one of these properties:

media.URL {string}: the url of the image to be edited (e.g. https://my-site.com/full-width1-e1.jpg). Use this approach if you want to load and edit a remote image file.

or

media.src {string}: the object url of the image to be edited. Use this approach if you want to edit a local image file (e.g. uploaded file or blob).

It can also contain these optional properties (with defaults if not set):

  • media.file {string}: the base name of the edited image file (e.g. full-width1-e1.jpg), defaults to default
  • media.ID {number}: An ID of the media item.
  • media.mime_type {string}: the MIME of the edited image (e.g. image/jpeg), defaults to image/png
  • media.title {string}: the title of the edited image (e.g. some image file), defaults to default

defaultAspectRatio

Typestring
RequiredNo
Default'FREE'

Default, pre-selected aspect ratio for the image editor. If allowedAspectRatios prop is present as well, it must include the defaultAspectRatio. For the list of all possible aspect ratios, see client/state/editor/image-editor/constants.

allowedAspectRatios

Typearray
RequiredNo
Defaultall possible aspect ratios

List allowed aspect ratios user can select when editing an image. If there is only a single specified aspect ratio in the allowedAspectRatios array, it will be set as defaultAspectRatio as well. For the list of all possible aspect ratios, see client/state/editor/image-editor/constants.

onDone

TypeFunction
RequiredNo

A function which will get called on extracting an edited image after clicking the "Done" button. It receives three arguments:

  • a JS Error object if image is not loaded/present, otherwise null
  • the extracted image in form of Blob object or null if image is not loaded/present
  • the props of the image editor which include image meta and functions to reset image editor state (for the full list, have a look into the image-editor/index file)

onCancel

TypeFunction
RequiredNo

A function which will get called on clicking the "Cancel" image editor button. If this prop is omitted, the "Cancel" button won't be rendered. The function receives one argument: the props of the image editor.

onReset

TypeFunction
RequiredNo

A function which will get called on clicking the "Reset" image editor button. The function is called after image editor's state is reset. The function receives one argument: the props of the image editor.

className

Typestring
RequiredNo

String of classes (class names) appended to the image editor wrapper (.image-editor [className]).

doneButtonText

Typestring
RequiredNo

Already-translated string which will be used on the 'Done' button. If not used, it will default to 'Done'.

Example

import ImageEditor from 'calypso/blocks/image-editor';

function render() {
    return <ImageEditor siteId={ siteId } media={ { URL: 'http://example.com/image.jpg' } } />;
}