-
|
Hello, According to the documentation, we need this to set a custom size for the I am not sure actually how to set those options, here is my code, which works so far regarding the cropping. import { Controller } from "@hotwired/stimulus";
import Cropper from "cropperjs";
export default class extends Controller {
static targets = ["image", "data", "result"];
connect() {
this.cropper = new Cropper(this.imageTarget, {
});
const cropperSelection = document.querySelector("cropper-selection");
if (cropperSelection) {
cropperSelection.setAttribute("x", 10);
cropperSelection.setAttribute("y", 10);
cropperSelection.setAttribute("width", 10);
cropperSelection.setAttribute("height", 10);
cropperSelection.movable = false;
cropperSelection.resizable = false;
}
const cropperCanva = this.cropper.getCropperCanvas();
if (cropperCanva) {
cropperCanva.style.minHeight = '400px';
cropperCanva.style.width = '400px';
}
}
crop() {
const cropperSelection = document.querySelector("cropper-selection");
cropperSelection.$toCanvas().then((croppedCanvas) => {
if (!croppedCanvas) {
console.error("Error : `$toCanvas()` failed.");
return;
}
this.resultTarget.innerHTML = "";
this.resultTarget.appendChild(croppedCanvas);
}).catch((error) => {
console.error("Error:", error);
});
}
}Note that those options are working correctly : cropperSelection.movable = false;
cropperSelection.resizable = false;I've also tried those variants, with no better results : const cropperSelection = document.querySelector("cropper-selection");
if (cropperSelection) {
cropperSelection.x = 10;
cropperSelection.y = 10;
cropperSelection.width = 10;
cropperSelection.height = 10;
cropperSelection.movable = false;
cropperSelection.resizable = false;
}and using pixels gives unstable results about the selection area, and disables I am actually not sure I am using the lib in a correct way. Thanks ! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Answering myself, if that can be any useful to anyone, I found the issue. I had to remove the attribute const cropperSelection = document.querySelector("cropper-selection");
if (cropperSelection) {
cropperSelection.removeAttribute("initial-coverage")
cropperSelection.x = 20;
cropperSelection.y = 70;
cropperSelection.width = 100;
cropperSelection.height = 100;
cropperSelection.movable = false;
cropperSelection.resizable = false;
} |
Beta Was this translation helpful? Give feedback.


Answering myself, if that can be any useful to anyone, I found the issue.
I had to remove the attribute
initial-coveragewhich was actually setting the position