gnu-social/public/assets/javascript/cropping.js

27 lines
903 B
JavaScript
Raw Normal View History

var input = document.getElementById('save_avatar');
var container = document.getElementById('img-container');
var cropImage = document.getElementById('img-cropped');
var cropped = document.getElementById('save_hidden');
2020-08-05 19:07:38 +01:00
input.addEventListener('change', function (e) {
if (!input.files || !input.files[0]) return;
var reader = new FileReader()
reader.onload = function (e) {
container.style = 'display: block';
cropImage.setAttribute('src', e.target.result);
2020-08-05 19:07:38 +01:00
function update() {
var croppedCanvas = cropper.getCroppedCanvas();
cropped.value = croppedCanvas.toDataURL();
input.files = undefined;
2020-08-05 19:07:38 +01:00
}
var cropper = new Cropper(cropImage, {
aspectRatio: 1,
viewMode: 1,
cropend: update,
ready: update,
})
}
reader.readAsDataURL(input.files[0]);
});