docs/api/cropper-image.md
The CropperImage interface provides properties and methods for manipulating the layout and presentation of <cropper-image> elements.
:::live-demo
<cropper-image></cropper-image>
:::
:::tip
The default width and height of this element is 0.
:::
:::live-demo
<cropper-image src="/cropperjs/picture.jpg" alt="Picture" style="width: 100%;" rotatable scalable skewable translatable></cropper-image>
:::
::: details <<< @/.vitepress/components/CropperImageExample.vue :::
Inherits properties from its parent, CropperElement, and implements the following properties:
| Name | Type | Default | Options | Description |
|---|---|---|---|---|
| initial-center-size | string | "contain" | "contain", "cover" | Indicates the initial size of the image when aligned with the center of its parent element. |
| rotatable | boolean | false | - | Indicates whether this element is rotatable. |
| scalable | boolean | false | - | Indicates whether this element is scalable. |
| skewable | boolean | false | - | Indicates whether this element is skewable. |
| slottable | boolean | false | - | Indicates whether this element is slottable. |
| translatable | boolean | false | - | Indicates whether this element is translatable. |
The built-in `` element will inherit the following attributes by default:
altcrossorigindecodingelementtimingfetchpriorityloadingreferrerpolicysizessrcsrcsetSyntax:
$ready()$ready(callback)Arguments:
callback:
FunctionReturns:
PromiseExample:
const cropperImage = new CropperImage();
cropperImage.$ready((image) => {
console.log(image.naturalWidth, image.naturalHeight);
});
cropperImage.src = '/cropperjs/picture.jpg';
Defers the callback to execute after successfully loading the image.
$center()$center(size)size:
string"contain", and "cover".CropperImageAligns the image to the center of its parent element.
$move(x)$move(x, y)x:
numbery:
numberxCropperImageMoves the image.
$moveTo(x)$moveTo(x, y)x:
numbery:
numberxCropperImageMoves the image to a specific position.
$rotate(angle)angle:
number | stringrad.x:
numbery:
numberCropperImage$rotate(0.8)$rotate('0.8rad')$rotate('45deg')$rotate('50grad')$rotate('0.1turn')$rotate('90deg', 0, 0)Rotates the image. It is similar to CSS function rotate() or CanvasRenderingContext2D.rotate().
Syntax:
$zoom(scale)$zoom(scale, x, y)Arguments:
scale:
numberx:
numbery:
numberReturns:
CropperImageExamples:
cropperImage.$zoom(0.1); // Zoom in 10%
cropperImage.$zoom(-0.1); // Zoom out 10%
cropperImage.$zoom(0.1, 0, 0); // Zoom in from the top-left corner
cropperImage.$zoom(-0.1, 0, 0); // Zoom out from the top-left corner
Zooms the image.
Syntax:
$scale(x)$scale(x, y)Arguments:
x:
numbery:
numberxReturns:
CropperImageExamples:
cropperImage.$scale(1.1); // Zoom in 10%
cropperImage.$scale(0.9); // Zoom out 10%
cropperImage.$scale(-1); // Flip both the horizontal and vertical directions
cropperImage.$scale(-1, 1); // Flip the horizontal direction
cropperImage.$scale(1, -1); // Flip the vertical direction
Scales the image. It is similar to CSS function scale() or CanvasRenderingContext2D.scale().
$skew(x)$skew(x, y)x:
number | stringrad.y:
number | stringxrad.CropperImage$skew(0.8)$skew('0.8rad')$skew('45deg')$skew('50grad')$skew('0.1turn')$skew(0, 0.8)Skews the image. It is similar to CSS function skew().
$translate(x)$translate(x, y)x:
numbery:
numberxCropperImageTranslates the image. It is similar to CSS function translate() or CanvasRenderingContext2D.translate().
$transform(a, b, c, d, e, f)a:
numberb:
numberc:
numberd:
numbere:
numberf:
numberCropperImageTransforms the image. It is similar to CSS function matrix() or CanvasRenderingContext2D.transform().
$setTransform(a, b, c, d, e, f)$setTransform(a)a:
number | Arrayb:
numberc:
numberd:
numbere:
numberf:
numberCropperImageResets (overrides) the current transform to the specific identity matrix, and then invokes a transform described by the arguments of this method. This lets you scale, rotate, translate (move), and skew the context. It is similar to CanvasRenderingContext2D.setTransform().
$getTransform()ArrayRetrieves the current transformation matrix being applied to the element. It is similar to CanvasRenderingContext2D.getTransform().
$resetTransform()$setTransform(1, 0, 0, 1, 0, 0)$setTransform([1, 0, 0, 1, 0, 0])CropperImageResets the current transform to the initial identity matrix. It is similar to CanvasRenderingContext2D.resetTransform().
truetruetrueObjectArrayArrayThe event is fired when the transform CSS property of the element is going to change.
There are no available slots in this element.
You can enable the default slot by setting the
slottableproperty totrue:html<cropper-image slottable></cropper-image>