That’s what I did. Replace the dataUrl.
This is not how I would approach a cropper integration nowadays. I will refactor everything into a custom component as I will need for my current project.
Anyway, I hope you can make sense of this.
<script>
var image = document.getElementById('profile_photo');
var cropBoxData;
var canvasData;
var cropper;
var c;
function cropInit() {
dmx.app.set('cropped', false);
original = dmx.app.data.view2.s3upload1.file.dataUrl;
cropper = new Cropper(image, {
dragMode: 'move',
restore: false,
guides: false,
center: false,
highlight: false,
cropBoxMovable: false,
cropBoxResizable: false,
toggleDragModeOnDblclick: false,
aspectRatio: 1 / 1,
autoCropArea: 0.5,
ready: function () {
//Should set crop box data first here
cropper.setCropBoxData(cropBoxData).setCanvasData(canvasData);
cropper.reset();
}
});
}
function cropDestroy() {
cropBoxData = cropper.getCropBoxData();
canvasData = cropper.getCanvasData();
cropper.destroy();
dmx.parse('s3upload1.reset()')
}
function crop() {
dmx.app.data.view2.s3upload1.file.dataUrl = cropper.getCroppedCanvas({"width" : "200", "height" : "200", "imageSmoothingQuality" : "high", "imageSmoothingEnabled" : true}).toDataURL("image/jpeg");
dmx.app.set('cropped', true);
cropper.getCroppedCanvas({"width" : "200", "height" : "200", "imageSmoothingQuality" : "high", "imageSmoothingEnabled" : true}).toBlob(function(blob) {
document.getElementById('s3upload1').dmxComponent.file = new File([blob], "profile.jpeg", { lastModified: new Date().getTime(), type: blob.type });
}, 'image/jpeg', 0.8);
}
function cancel() {
dmx.app.data.view2.s3upload1.file.dataUrl = original;
dmx.app.set('cropped', false);
}
</script>