Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The jCrop plugin does most of the work. You just need a little logic to stitch it together with a slider widget (like the jqueryui slider).</p> <p>Here's a quick and dirty example. You'll certainly want to host the files on your own server, but I just wanted to throw something together.</p> <p>One significant difference is that this code forgets where you have dragged the selection and just resizes it around the current midpoint. If that is important to you, you could probably add that functionality pretty easily.</p> <pre> &lt;html&gt; &lt;head&gt; &lt;link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" /&gt; &lt;script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.slider.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.slider.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://deepliquid.com/projects/Jcrop/js/jquery.Jcrop.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="http://deepliquid.com/projects/Jcrop/css/jquery.Jcrop.css" type="text/css" /&gt; &lt;style type="text/css"&gt; #slider { margin: 10px; } &lt;/style&gt; &lt;script type="text/javascript"&gt; var jcrop_api; $(document).ready(function(){ imgwidth = $("#cropbox").width(); imgheight = $("#cropbox").height(); aspectRatio=(imgheight &gt; 0)?imgwidth / imgheight:1; jcrop_api = $.Jcrop('#cropbox',{ setSelect: [ 0, 0, imgwidth, imgheight ], aspectRatio: aspectRatio }); $("#slider").slider({ min: 0, max: 100, value: 100, slide: function(e,ui){ updateCrop(ui.value); } }); function updateCrop(size){ size = size / 100; maxX = $("#cropbox").width(); maxY = $("#cropbox").height(); midX = ((jcrop_api.tellSelect().x2 - jcrop_api.tellSelect().x) / 2) + jcrop_api.tellSelect().x; midY = ((jcrop_api.tellSelect().y2 - jcrop_api.tellSelect().y) / 2) + jcrop_api.tellSelect().y; midX = (midX &lt; 0) ? midX * -1 : midX; midY = (midY &lt; 0) ? midY * -1 : midY; sizeX = $("#cropbox").width() * size; sizeY = $("#cropbox").height() * size; x = midX - (sizeX/2); y = midY - (sizeY/2); x2 = midX + (sizeX/2); y2 = midY + (sizeY/2); // edge conditions if (x &lt; 0){ x2 -= x2 - x; x = 0; if (x2 &gt; maxX) x2 = maxX; } if (x2 &gt; maxX){ x -= (x2 - maxX); x2 = maxX; if (x &lt; 0) x = 0; } if (y &lt; 0){ y2 -= y; y = 0; if (y2 &gt; maxY) y2 = maxY; } if (y2 &gt; maxY){ y -= (y2 - maxY); y2 = maxY; if (y &lt; 0) y = 0; } jcrop_api.setSelect([ x,y,x2,y2 ]); } }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;img src="http://deepliquid.com/projects/Jcrop/demos/demo_files/sago.jpg" id="cropbox" /&gt; &lt;div id="slider"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload