@nichoth/image-crop-element
TypeScript icon, indicating that this package has built-in type declarations

5.0.5 • Public • Published

<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 i --S @nichoth/image-crop-element

fork

This is a fork of @github/image-crop-element.

aspect ratio

You can pass in an aspect ratio attribute:

<image-crop
    aspectratio="4 / 5"
    src="100.jpg"
></image-crop>

This will constrain the image crop border to the given ratio.

Usage

Plain

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

Rounded crop area

<image-crop src="/avatar.jpg" rounded></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
  )
})

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
5.0.50latest

Version History

VersionDownloads (Last 7 Days)Published
5.0.50
5.0.40
5.0.30
5.0.00

Package Sidebar

Install

npm i @nichoth/image-crop-element

Weekly Downloads

0

Version

5.0.5

License

MIT

Unpacked Size

31 kB

Total Files

10

Last publish

Collaborators

  • nichoth