0.19.6 • Published 2 months ago

react-advanced-cropper v0.19.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

:warning: It's the beta version. The API can be changed in the future. Therefore, it's recommended to fix the version with ~.


React Advanced Cropper is the advanced library that gives you opportunity to create your own croppers suited for any website design. It means that you are able to change not only the cropper appearance, you area able to customize its behavior also.

Features:

  • full mobile / desktop support
  • support all three main types of croppers right out of the box
  • support both canvas and coordinates modes, minimum and maximum aspect ratios, custom size restrictions
  • zoom, rotate, resize image
  • auto-zoom, transitions

npm.io

Install

npm install --save react-advanced-cropper
yarn add react-advanced-cropper

Usage

import React, { useState } from 'react';
import { CropperRef, Cropper } from 'react-advanced-cropper';
import 'react-advanced-cropper/dist/style.css'

export const GettingStartedExample = () => {
	const [image, setImage] = useState(
		'https://images.unsplash.com/photo-1599140849279-1014532882fe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1300&q=80',
	);

	const onChange = (cropper: CropperRef) => {
		console.log(cropper.getCoordinates(), cropper.getCanvas());
	};

	return (
		<Cropper
			src={image}
			onChange={onChange}
			className={'cropper'}
		/>
	)
};
/*
  Maybe you need to set the limits for the cropper sizes or its container sizes
  otherwise a cropping image will try to fill all available space
*/
.cropper {
  height: 600px;
  background: #DDD;
}

Cropper

PropTypeDescriptionDefault
srcstringThe cropping image (link / base64)
stencilComponentComponentThe stencil componentRectangleStencil
stencilPropsobjectThe props for the stencil component{}
classNamestringThe optional class for the root cropper block
imageClassNamestringThe optional class for the cropping image
boundariesClassNamestringThe optional class for the area.
backgroundClassNamestringThe optional class for the background under the image
autoZoombooleanEnable / disable transitionstrue
transitionsboolean, objectEnable / disable auto zoomfalse
stencilSizeobjectThe size of the stencil in pixels
canvasbooleanThe flag that indicates if canvas should be usedtrue
minWidthnumberThe minimum width of the stencil (percents)
minHeightnumberThe minimum height of the stencil (percents)
maxWidthnumberThe maximum width of the stencil (percents)
maxHeightnumberThe maximum height of the stencil (percents)
checkOrientationbooleanCheck if EXIF orientation should be checkedtrue
resizeImageboolean, objectThe options for the image resizing (details)true
moveImageboolean, objectThe options for the image moving (details)true
rotateImageboolean, objectThe options for the image moving (details)false
imageRestrictionstringSet restrictions for image position ('fillArea' 'fitArea', 'stencil', 'none')'fillArea'
defaultSizeobject, FunctionThe function that returns the default size of the stencil or object
defaultPositionobject, FunctionThe function that returns the default position of the stencil or object
defaultTransformsobject, FunctionThe function that returns the default image transforms or object
wrapperComponentComponentThe wrapper componentCropperWrapper
wrapperPropsobjectThe props for the wrapper component{}
backgroundWrapperComponentComponentThe background wrapper componentCropperBackgroundWrapper
backgroundWrapperPropsobjectThe props for the background wrapper component{}

See the documentation for more props and details.

RectangleStencil

PropTypeDescriptionDefault
aspectRationumberThe aspect ratio
minAspectRationumberThe minimum aspect ratio
maxAspectRationumberThe maximum aspect ratio
classNamestringThe class for root block of the stencil component
previewClassNamestringThe class for the preview component
movingClassNamestringThe class applied when user drag the stencil
resizingClassNamestringThe class applied when user resize the stencil
boundingBoxClassstringThe class for the bounding box component
handlerComponentComponentThe handler component
handlersobjectThe object of handlers that should be visible or hidden.
handlerClassNamesobjectThe object of custom handler classes
handlerWrapperClassNamesobjectThe object of custom handler wrapper classes
lineComponentComponentThe handler component
linesobjectThe object of lines that should be visible or hidden.
lineClassNamesobjectThe object of custom line classes
lineWrapperClassNamesobjectThe object of custom line wrapper classes

See the documentation for more props and details.

License

The source code of this library is licensed under MIT, the documentation content belongs to Norserium, except the photos that belong to their respective owners.

0.19.5

2 months ago

0.19.6

2 months ago

0.19.4

7 months ago

0.19.0

1 year ago

0.19.2

1 year ago

0.19.3

1 year ago

0.18.0

1 year ago

0.15.0

2 years ago

0.17.0

1 year ago

0.14.0

2 years ago

0.16.0

2 years ago

0.16.1

2 years ago

0.11.0

2 years ago

0.11.1

2 years ago

0.13.0

2 years ago

0.11.2

2 years ago

0.11.3

2 years ago

0.11.4

2 years ago

0.12.0

2 years ago

0.12.1

2 years ago

0.10.5

2 years ago

0.8.9

2 years ago

0.8.8

2 years ago

0.8.5

2 years ago

0.8.4

2 years ago

0.8.7

2 years ago

0.8.6

2 years ago

0.10.1

2 years ago

0.10.2

2 years ago

0.10.3

2 years ago

0.10.4

2 years ago

0.8.10

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.1

2 years ago

0.7.2

2 years ago

0.8.0

2 years ago

0.7.1

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.7.3

2 years ago

0.7.0

2 years ago

0.6.2

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.6.1

2 years ago

0.5.2

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.2

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.3

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.2.2

2 years ago

0.1.1

3 years ago

0.1.0

3 years ago