cropper JS을 사용하여 이미지를 자릅니다. 그러나 캔버스의 너비와 높이를 가져올 수는 있지만 자른 이미지의 좌표 (X와 Y)를 알아야합니다.CropperJS의 자른 이미지 좌표를 얻는 방법은 무엇입니까?
은 여기 내 코드 -
(function() {
//getting ratio
function getImageRatio(sourceCanvas) {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var width = sourceCanvas.width;
var height = sourceCanvas.height;
canvas.width = width;
canvas.height = height;
context.beginPath();
context.arc(width/2, height/2, Math.min(width, height)/2, 0, 2 * Math.PI);
context.strokeStyle = 'rgba(0,0,0,0)';
context.stroke();
context.clip();
context.drawImage(sourceCanvas, 0, 0, width, height);
return canvas;
}
window.addEventListener('DOMContentLoaded', function() {
var image = document.getElementById('image');
var button = document.getElementById('button');
var result = document.getElementById('result');
var croppable = false;
var cropper = new Cropper(image, {
aspectRatio: 1,
viewMode: 1,
built: function() {
croppable = true;
}
});
button.onclick = function() {
var croppedCanvas;
var roundedCanvas;
var roundedImage;
if (!croppable) {
return;
}
// Crop
croppedCanvas = cropper.getCroppedCanvas();
console.log(getImageRatio(croppedCanvas));
};
});
})();
어떤 생각, 어떻게 PHP로 이미지를 자르 할 수 있도록 자른 이미지의 좌표를 얻을 수있다.
나는 왜 어떤 사람들은 항상 부정적인 마음을 가지고 있는지 모르겠다! 투표를하는 이유는 무엇입니까? – tisuchi