我剛剛在一個項目上使用了cropperjs(https://fengyuanchen.github.io/cropperjs/),並且非常滿意。它不使用jQuery。
這裏有一對夫婦的功能我寫信給初始化栽跟頭,然後得到裁剪後的圖像:
function initCropper() {
// create blob url from file object
vm.selectedImage.dataUrl = URL.createObjectURL(vm.selectedImage);
$timeout(function() {
// initialise cropper
var image = document.getElementById(vm.modalId + '-image');
vm.cropper = new Cropper(image, {
aspectRatio: $scope.width/$scope.height,
minContainerHeight: Number($scope.height) + 200,
guides: false,
cropBoxResizable: false,
cropBoxMovable: false,
zoomable: true,
dragMode: 'move',
toggleDragModeOnDblclick: false,
checkOrientation: false,
responsive: false,
built: function() {
// revoke blob url after cropper is built
URL.revokeObjectURL(vm.selectedImage.dataUrl);
}
});
});
}
function cropImage() {
// get cropped image and pass to output file
vm.cropper
.getCroppedCanvas({ width: $scope.width, height: $scope.height })
.toBlob(function (croppedImage) {
$timeout(function() {
croppedImage.name = vm.selectedImage.name;
vm.croppedImage = croppedImage;
vm.croppedImage.dataUrl = URL.createObjectURL(croppedImage);
$scope.outputFile = vm.croppedImage;
// destroy cropper
vm.cropper.destroy();
vm.cropper = null;
vm.selectedImage = null;
});
}, 'image/jpeg');
}
的功能是從一個角度指令,它就是爲什麼有到$範圍,$超時和VM引用,但角度不是必需的。
謝謝,我自己找到了croppieJs,但對線程有霧點。標記爲下一個正在搜索的人的解決方案 – simon