裁剪器没有重新启动如果我不首先裁剪旧图像

时间:2018-11-14 05:52:19

标签: javascript jquery cropper cropperjs

我的项目有问题。

我正在使用裁纸器进行图像处理。但是收割机工作不正常。当我上传图像时,将显示裁剪选项。但是,如果我添加的第一个图像没有裁剪,则裁剪器不会更改图像。

这是我的代码

function initCropper(){
    var crop_button_show = document.getElementById("crop_button_show");
    crop_button_show.style.display = "block";
    var image = document.getElementById('thumbnail_preview');
    var cropper = new Cropper(image, {   
        viewMode: 3,
        aspectRatio: 500/410,
        cropBoxResizable: false,
        minCropBoxWidth: 500,
        minCropBoxHeight: 410, 
    });

    document.getElementById('crop_button').addEventListener('click', function(){
        var imgurl =  cropper.getCroppedCanvas().toDataURL();
        var img = document.createElement("img");
        img.class = "img-responsive show-preview";
        img.src = imgurl;
        img.id = "thumbnail_preview";
        jQuery("#image_resize").empty();
        jQuery("#image_resize").append(img);

        var input = document.createElement("input");
        input.name = "image";
        input.type = "hidden";
        jQuery("#image_resize").append(input);
        $('input[name=image]').val(imgurl.replace('data:image/png;base64,', ''));
        crop_button_show.style.display = "none";
    });
}

我不知道第二次从哪里重置播种机。如果我裁切图像,然后重新上传imgae,则裁切器运行正常。

0 个答案:

没有答案