kennygit / jcrop

Automatically exported from code.google.com/p/jcrop
0 stars 0 forks source link

minSize with aspect ratio set doesn't work #8

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Set the minSize in width and height
2. Set the aspect ratio in the options
3. resize, and you'll notice minSize is ignored

What is the expected output? What do you see instead?
I would expect minSize to be adhered to.

What version of the product are you using? On what operating system?
version .95. on a mac osx with ff3.

Please provide any additional information below.
the getFixed function is where the min size is supposed to be implemented
if the aspect ratio is set, but it's not implemented at all (it only is in
getRect(), but that doesn't apply when the aspect ratio is set).

Original issue reported on code.google.com by eski...@gmail.com on 13 Jan 2009 at 4:45

GoogleCodeExporter commented 8 years ago
I figured out if i change getFixed to the following, it works (this is not 
optimized
by any means). Also I'm not sure if copying and pasting the code in will mess 
with
the formatting.

function getFixed()
        {
            if (!options.aspectRatio && !aspectLock) return getRect();

            // This function could use some optimization I think...
            var aspect = options.aspectRatio ? options.aspectRatio : aspectLock,
                min = options.minSize,
                max = options.maxSize,
                rw = x2 - x1,
                rh = y2 - y1,
                rwa = Math.abs(rw),
                rha = Math.abs(rh),
                real_ratio = rwa / rha,
                xx, yy
            ;

            if (real_ratio < aspect)
            {
                yy = y2;
                w = rha * aspect;
                xx = rw < 0 ? x1 - w : w + x1;
                rwa = Math.abs(xx-x1)
                h = rwa / aspect;
                //new//
                if(xmin && (rwa < xmin))
                    xx = (rw > 0) ? (x1 + xmin) : (x1 - xmin);
                if(ymin && (rha < ymin))
                    yy = (rh > 0) ? (y1 + ymin) : (y1 - ymin);
                //end new//
                if (xx < 0)
                {
                    xx = 0;
                    h = Math.abs((xx - x1) / aspect);
                    yy = rh < 0 ? y1 - h: h + y1;
                    //new//
                    if(xmin && (rwa < xmin))
                        xx = (rw > 0) ? (x1 + xmin) : (x1 - xmin);
                    if(ymin && (rha < ymin))
                        yy = (rh > 0) ? (y1 + ymin) : (y1 - ymin);
                    //end new//
                }
                else if (xx > boundx)
                {
                    xx = boundx;
                    h = Math.abs((xx - x1) / aspect);
                    yy = rh < 0 ? y1 - h : h + y1;
                    //new//
                    if(xmin && (rwa < xmin))
                        xx = (rw > 0) ? (x1 + xmin) : (x1 - xmin);
                    if(ymin && (rha < ymin))
                        yy = (rh > 0) ? (y1 + ymin) : (y1 - ymin);
                    //end new//
                }
            }
            else
            {
                xx = x2;
                h = rwa / aspect;
                yy = rh < 0 ? y1 - h : y1 + h;
                rha = Math.abs(yy-y1)
                w = rha * aspect;
                //new//
                if(xmin && (rwa < xmin))
                    xx = (rw > 0) ? (x1 + xmin) : (x1 - xmin);
                if(ymin && (rha < ymin))
                    yy = (rh > 0) ? (y1 + ymin) : (y1 - ymin);
                //end new//
                if (yy < 0)
                {
                    yy = 0;
                    w = Math.abs((yy - y1) * aspect);
                    xx = rw < 0 ? x1 - w : w + x1;
                    //new//
                    if(xmin && (rwa < xmin))
                        xx = (rw > 0) ? (x1 + xmin) : (x1 - xmin);
                    if(ymin && (rha < ymin))
                        yy = (rh > 0) ? (y1 + ymin) : (y1 - ymin);
                    //end new//
                }
                else if (yy > boundy)
                {
                    yy = boundy;
                    w = Math.abs(yy - y1) * aspect;
                    xx = rw < 0 ? x1 - w : w + x1;
                    //new//
                    if(xmin && (rwa < xmin))
                        xx = (rw > 0) ? (x1 + xmin) : (x1 - xmin);
                    if(ymin && (rha < ymin))
                        yy = (rh > 0) ? (y1 + ymin) : (y1 - ymin);
                    //end new//
                }
            }
            return last = makeObj(flipCoords(x1,y1,xx,yy));
        };

Original comment by eski...@gmail.com on 13 Jan 2009 at 4:48

GoogleCodeExporter commented 8 years ago
even i am getting the same issue

Original comment by a.saan...@gmail.com on 2 Jun 2010 at 11:22

GoogleCodeExporter commented 8 years ago
For me it only happens when I init jcrop with setSelect. Sadly I need the 
setSelect property.

This works:

$('#cropbox').Jcrop({
    trueSize: [1024, 768],
    aspectRatio: previewAspect,
    allowSelect: true,
    minSize: [640, 300],
    maxSize: [1024, 768],
    /*setSelect: [10, 10, 380, 140],*/
    onChange: showPreview,
    onSelect: showPreview
});

Using .98

Original comment by christof...@gmail.com on 23 Jun 2010 at 10:06

GoogleCodeExporter commented 8 years ago
I just fixed it by moving this block down (just before Selection.refresh();):

if ('setSelect' in options) {
    setSelect(opt.setSelect);
    Selection.done();
    delete(options.setSelect);
}

Original comment by christof...@gmail.com on 23 Jun 2010 at 10:16