Tambahkan kode JS sebelum penutup tag body
document.addEventListener("DOMContentLoaded", function () {
const image = document.getElementById('imagecan');
const inputImage = document.getElementById('inputImage');
let cropper;
function initializeCropper(imageUrl) {
image.src = imageUrl;
if (cropper) {
cropper.destroy();
}
cropper = new Cropper(image, {
aspectRatio: 16 / 9,
viewMode: 1,
autoCropArea: 1,
cropBoxMovable: true,
cropBoxResizable: true,
});
}
const initialImageUrl = 'default-image-url.jpg';
initializeCropper(initialImageUrl);
inputImage.addEventListener('change', function (event) {
const files = event.target.files;
if (files && files.length > 0) {
const reader = new FileReader();
reader.onload = function (e) {
initializeCropper(e.target.result);
};
reader.readAsDataURL(files[0]);
}
});
});