简体   繁体   English

旋转未定义cropper.js

[英]rotate is not defined cropper.js

I am using the awesome jquery-cropper plugin from fengyuanchen. 我正在使用fengyuanchen的超棒jquery-cropper插件。

I'm having the issue of when certain images get uploaded it rotates and it is not on the right side which I have to make the user rotate them. 我遇到的问题是,何时上传某些图像时它会旋转,而它不在右侧,我必须让用户旋转它们。 I will upload the image via ajax . 我将通过ajax上传图像。 I'm getting the error rotate is not defined which I have been stuck a couple of hours. 我遇到了错误rotate is not defined ,我被困了几个小时。

$('#profilePhoto').on( 'change', function(){
            if (this.files && this.files[0]) {
                if ( this.files[0].type.match(/^image\//) ) {
                    var reader = new FileReader();
                    reader.onload = function(evt) {
                        var img = new Image();
                        img.onload = function() {
                            $("#profileImageContainer").hide();
                            $("#rotateImg").show();
                            context.canvas.height = img.height;
                            context.canvas.width  = img.width;
                            context.drawImage(img, 0, 0);
                            cropper = canvas.cropper({
                                aspectRatio: 1 / 1,
                                rotatable: true,
                            });

                            $('#btnCrop').click(function() {
                                // Get a string base 64 data url
                                var croppedImageDataURL = canvas.cropper('getCroppedCanvas').toDataURL("image/png");
                            });

                            $('#rotateImg').click(function () {
                                cropper.cropper.rotate(90);
                            });
                        };
                        img.src = evt.target.result;
                    };
                    reader.readAsDataURL(this.files[0]);
                }
                else {
                    alert("Invalid file type! Please select an image file.");
                }
            }
            else {
                alert('No file(s) selected.');
            }
        });

The main problem here is about scopes since it looks like it is not reconizing the cropper variable. 这里的主要问题是关于范围的,因为它似乎没有在重新调整裁剪器变量。

This problems surfaces because when the user upload a photo sometimes this photo rotate automatically. 之所以会出现此问题,是因为当用户上传照片时,该照片有时会自动旋转。 If I could solve this problem first without having to make the user rotate the image would be better 如果我可以先解决此问题而不必让用户旋转,那图像会更好

Really stupid mistake. 真是愚蠢的错误。 Instead of: 代替:

cropper.cropper().rotate(90);

I should apply: 我应该申请:

cropper.cropper('rotate', 90);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM