Home
Softono

Image Crop Element

Open source MIT TypeScript
196
Stars
25
Forks
3
Issues
237
Watchers
2 months
Last Commit

 About Image Crop Element

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

Platforms

Web Self-hosted

Languages

TypeScript

Need Help Installing Image Crop Element?

We provide expert installation service for this software. Our team will install, configure, and secure Image Crop Element on your server. plans start at just $30.

Image Crop Element

View on GitHub

<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="https://raw.githubusercontent.com/github/image-crop-element/main/avatar.jpg"></image-crop>

Rounded crop area

<image-crop src="https://raw.githubusercontent.com/github/image-crop-element/main/avatar.jpg" rounded></image-crop>

With loading state

<image-crop src="https://raw.githubusercontent.com/github/image-crop-element/main/avatar.jpg">
  <img src="https://raw.githubusercontent.com/github/image-crop-element/main/spinner.gif" alt="" data-loading-slot />
</image-crop>

With autoupdate inputs

<image-crop src="https://raw.githubusercontent.com/github/image-crop-element/main/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
  )
})

CSS encapsulation

The elements HTML structure is initialized in a Shadow DOM, so it is impossible to apply CSS to it. If you need to change the element's default style for any reason, you should open up a new issue (or a pull request!), describing your use case, and we'll work with you on solving the problem.

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