tel8618217223380 / jcrop

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

minSize does not respect trueSize #43

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set trueSize in a setOptions call with larger dimensions than the displayed 
size
2. Set minSize in a subsequent call (or the same call) using dimensions of the 
original image
3. Observe that the minimum size is in displayed pixels, not relative to 
trueSize. Or, if you set minimumSize bigger than the display dimensions (not 
bigger than trueSize), the left edge of the crop rectangle is pushed out of view

What is the expected output? What do you see instead?

See above

What version of the product are you using? On what operating system?

I have the latest tarball download, 0.9.8

Please provide any additional information below.

Chrome 6 for Mac

Original issue reported on code.google.com by tom%punk...@gtempaccount.com on 18 Oct 2010 at 8:07

GoogleCodeExporter commented 9 years ago
More information and a patch.

The bug is specific (so far anyway) to the case where trueSize is set but 
aspectRatio is not. The getRect method assumes that xscale and yscale are not 
relevant, when in fact they need to be applied to xlimit, ylimit, xmin and ymin.

The patch follows.

Hope this is helpful - thanks for jcrop! We ship it in the Apostrophe open 
source CMS (www.apostrophenow.com)

Index: web/js/plugins/jquery.Jcrop.js
===================================================================
--- web/js/plugins/jquery.Jcrop.js  (revision 2442)
+++ web/js/plugins/jquery.Jcrop.js  (working copy)
@@ -1,4 +1,8 @@
 /**
+ *
+ * PATCHED by tom@punkave.com to address 
http://code.google.com/p/jcrop/issues/detail?id=43
+ * Please do not upgrade without including that patch unless the issue has 
been fixed upstream
+ * 
  * jquery.Jcrop.js v0.9.8
  * jQuery Image Cropping Plugin
  * @author Kelly Hallman <khallman@gmail.com>
@@ -361,15 +365,22 @@
            var xsize = x2 - x1;
            var ysize = y2 - y1;

-           if (xlimit && (Math.abs(xsize) > xlimit))
-               x2 = (xsize > 0) ? (x1 + xlimit) : (x1 - xlimit);
-           if (ylimit && (Math.abs(ysize) > ylimit))
-               y2 = (ysize > 0) ? (y1 + ylimit) : (y1 - ylimit);
+           // tom@punkave.com: x1 etc. are in display coordinates,
+           // so we need to scale xlimit, ylimit, ymin and xmin or
+           // they will lie to us. xscale and yscale come into play here
+           // when trueSize is set but aspectRatio is not
+           
+           var sxmin = xmin / xscale, symin = ymin / yscale, sxlimit = xlimit / 
xscale, sylimit = ylimit / yscale;
+           
+           if (sxlimit && (Math.abs(xsize) > sxlimit))
+               x2 = (xsize > 0) ? (x1 + sxlimit) : (x1 - sxlimit);
+           if (sylimit && (Math.abs(ysize) > sylimit))
+               y2 = (ysize > 0) ? (y1 + sylimit) : (y1 - sylimit);

-           if (ymin && (Math.abs(ysize) < ymin))
-               y2 = (ysize > 0) ? (y1 + ymin) : (y1 - ymin);
-           if (xmin && (Math.abs(xsize) < xmin))
-               x2 = (xsize > 0) ? (x1 + xmin) : (x1 - xmin);
+           if (symin && (Math.abs(ysize) < symin))
+               y2 = (ysize > 0) ? (y1 + symin) : (y1 - symin);
+           if (sxmin && (Math.abs(xsize) < sxmin))
+               x2 = (xsize > 0) ? (x1 + sxmin) : (x1 - sxmin);

            if (x1 < 0) { x2 -= x1; x1 -= x1; }
            if (y1 < 0) { y2 -= y1; y1 -= y1; }

Original comment by tom%punk...@gtempaccount.com on 18 Oct 2010 at 8:51