tapmodo / Jcrop

Jcrop - The Javascript Image Cropping Engine
https://jcrop.com
Other
4.31k stars 939 forks source link

jcrop.newCropper is not a function #304

Open nunoperalta opened 3 years ago

nunoperalta commented 3 years ago

In these examples:

https://jcrop.com/guide/widgets.html#creating-a-widget https://jcrop.com/guide/instance.html#newwidget-rect-options

const jcrop = Jcrop.attach('target');
const rect = Jcrop.Rect.fromPoints([100,100],[200,200]);
jcrop.newCropper(rect,{ aspectRatio: rect.aspect });

TypeError: jcrop.newCropper is not a function

I'm finding it really hard to get this working, and unfortunately the documentation is very confusing or incomplete. (eventually got this figured out)

Would be nice if the page at: https://jcrop.com/examples/ could have an example source code that I could copy from, as it seems to do exactly what I want.

I'm simply looking to put a default cropper active, centered to the image, with fixed aspect ratio.

manchumahara commented 2 years ago

@nunoperalta you wrote (eventually got this figured out). Can you share how you fixed ? I am also looking in docs but can not find solution exactly. More code based working example could help.

nunoperalta commented 2 years ago

Hey

I can't remember exactly, but here's what I have currently:

        Jcrop.load('img-to-crop').then(function (img) {
            var jcrop = Jcrop.attach(img);
            var rect = Jcrop.Rect.create(x, y, w, h);
            jcrop.newWidget(rect, { aspectRatio: rect.aspect });
            ...
            jcrop.destroy();
        });

The position can be accessed through jcrop.active.pos