I found on internet this imagecrop system.
This System normaly image upload and crop system. If i try code is working. But if i try change the function it doesnt work.
I have to change system.
I already uploaded image. And i wanna crop uploaded image.
Jscript
var $modal = $('#modal');
var image = document.getElementById('sample_image');
var cropper;
//$("body").on("change", ".image", function(e){
$('#upload_image').on("change", function(event){
var files = event.target.files;
var done = function (url) {
image.src = url;
$modal.modal('show');
};
//var reader;
//var file;
//var url;
if (files && files.length > 0)
{
/*file = files[0];
if(URL)
{
done(URL.createObjectURL(file));
}
else if(FileReader)
{*/
reader = new FileReader();
reader.onload = function (event) {
done(reader.result);
};
reader.readAsDataURL(files[0]);
//}
}
});
$modal.on('shown.bs.modal', function() {
cropper = new Cropper(image, {
aspectRatio: 1,
viewMode: 3,
preview: '.preview'
});
}).on('hidden.bs.modal', function() {
cropper.destroy();
cropper = null;
});
$("#crop").click(function(){
canvas = cropper.getCroppedCanvas({
width: 1600,
height: 400,
});
canvas.toBlob(function(blob) {
//url = URL.createObjectURL(blob);
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
var base64data = reader.result;
$.ajax({
url: "upload.php",
method: "POST",
data: {image: base64data},
success: function(data){
console.log(data);
$modal.modal('hide');
$('#uploaded_image').attr('src', data);
//alert("success upload image");
}
});
}
});
});
If you choice file from computer this system work and start image crop system.. But i dont want upload image.
I have a button like this :
<div><a href="#" class="cropimage" data="/images/resimler/testimage.jpg">Crop Image</a></div>
When I click on this a, I want to take the data of a and do the image crop on that image.
Thanks for help..