Directory

← Back

image-crop-element

A custom element for cropping a square image. Returns x, y, width, and height.

Author

Rating

Popularity

<100

<image-crop-element>

This loads an image and creates a crop area that user can modify. An event is fired with x, y, width, and height as the crop area changes.

Installation

$ npm install --save @github/image-crop-element

Usage

Plain

<image-crop src="/avatar.jpg"></image-crop>

With loading state

<image-crop src="/avatar.jpg">
  <img src="spinner.gif" alt="" data-loading-slot>
</image-crop>

With autoupdate inputs

<image-crop src="/avatar.jpg">
  <input type="hidden" data-image-crop-input="x" name="x">
  <input type="hidden" data-image-crop-input="y" name="y">
  <input type="hidden" data-image-crop-input="width" name="width">
  <input type="hidden" data-image-crop-input="height" name="height">
</image-crop>

Listen to the change event

document.addEventListener('image-crop-change', function (event){
  console.log(
    'Crop area changed.',
    event.detail.x,
    event.detail.y,
    event.detail.width,
    event.detail.height
  )
})

Browser support

Browsers without native custom element support require a polyfill. Legacy browsers require various other polyfills. See examples/index.html for details.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Dependencies

Released
2019-02-25
Maturity
IMPORTED
License
MIT License

Compatibility

Framework
Browser
Browser Independent

image-crop-element - Vaadin Add-on Directory

A custom element for cropping a square image. Returns x, y, width, and height. image-crop-element - Vaadin Add-on Directory
# <image-crop-element> This loads an image and creates a crop area that user can modify. An event is fired with x, y, width, and height as the crop area changes. ## Installation ``` $ npm install --save @github/image-crop-element ``` ## Usage ### Plain ```html ``` ### With loading state ```html ``` ### With autoupdate inputs ```html ``` ### Listen to the change event ```javascript document.addEventListener('image-crop-change', function (event){ console.log( 'Crop area changed.', event.detail.x, event.detail.y, event.detail.width, event.detail.height ) }) ``` ## Browser support Browsers without native [custom element support][support] require a [polyfill][]. Legacy browsers require various other polyfills. See [`examples/index.html`][example] for details. [example]: https://github.com/github/image-crop-element/blob/57080ad88d26e05b42fa10a95470da8035f53967/examples/polyfill.html#L17-L22 - Chrome - Firefox - Safari - Microsoft Edge [support]: https://caniuse.com/#feat=custom-elementsv1 [polyfill]: https://github.com/webcomponents/custom-elements
Online