Skip to content
A custom element for cropping a square image. Returns x, y, width, and height.
TypeScript JavaScript CSS
Branch: master
Clone or download

Latest commit

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Build on all pushes May 20, 2020
examples Convert to TypeScript May 20, 2020
src Add back HTMLElementTagNameMap May 22, 2020
test Remove network requirement from test May 20, 2020
.eslintrc.json Convert to TypeScript May 20, 2020
.gitignore
CODEOWNERS Create CODEOWNERS May 20, 2020
LICENSE Update license Jun 22, 2018
package-lock.json Merge branch 'master' into ts May 20, 2020
package.json Merge branch 'master' into ts May 20, 2020
readme.md
tsconfig.json Convert to TypeScript May 20, 2020

readme.md

<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
You can’t perform that action at this time.