Croppr.js icon indicating copy to clipboard operation
Croppr.js copied to clipboard

don't work in modal !

Open AkramZerarka opened this issue 5 years ago • 1 comments

When I insert the picture and I resize my window the cropper takes another width and height****

AkramZerarka avatar Oct 13 '19 00:10 AkramZerarka

For people finding this thread: the following TypeScript code works for me to dynamically resize the cropper using directly the .croppr-image and .croppr-imageClipped elements.

let lastKnownValue: Croppr.CropValue;
this.uploadedImageCropper = new Croppr(el, {
	// options
	// ...
	// store ratio value on update, needed for resize handling
	returnMode: "ratio",
	onCropEnd(data: Croppr.CropValue) {
		lastKnownValue = { ...data };
	},
	onInitialize(instance: Croppr) {
		// set the maximum height to (100vh - 15rem) to avoid scrolling
		let bounds = instance["imageEl"].getBoundingClientRect();
		instance["imageEl"].style.width = instance["imageClippedEl"].style.width =
			"calc((100vh - 15rem) * " + (Math.floor((bounds.width * 1000) / bounds.height) / 1000).toString() + ")";
		// handle resizing correctly
		lastKnownValue = instance.getValue();
		instance["resizeObserver"] = new ResizeObserver(() => {
			const bounds = instance["imageEl"].getBoundingClientRect();
			instance["box"].move(lastKnownValue.x * bounds.width, lastKnownValue.y * bounds.height);
			instance.resizeTo(lastKnownValue.width * bounds.width, lastKnownValue.height * bounds.height, [0, 0]);
		});
		instance["resizeObserver"].observe(instance["imageEl"]);
	},
});

Maybe that should be integrated directly into the library?

moqmar avatar Nov 06 '21 21:11 moqmar