Skip to content

Instantly share code, notes, and snippets.

@kaspergrubbe
Created September 27, 2013 15:54
Show Gist options
  • Save kaspergrubbe/6730806 to your computer and use it in GitHub Desktop.
Save kaspergrubbe/6730806 to your computer and use it in GitHub Desktop.
$('.jcrop').on('load', function(){
image = $(this);
ratio = image.data('ratio').split('x');
ratio = parseFloat(ratio[0]) / parseFloat(ratio[1]);
x1 = image.data('x1');
y1 = image.data('y1');
x2 = image.data('x2');
y2 = image.data('y2');
width = image.data('width');
height = image.data('height');
image.Jcrop({
setSelect: [ x1, y1, x2, y2 ],
aspectRatio: ratio,
trueSize: [width, height],
onChange: $.proxy( showCoords, this ),
onSelect: $.proxy( showCoords, this )
});
function showCoords(c)
{
var image = $(this);
var ratio = image.data('ratio');
$('#'+ratio+" .x1").val(c.x);
$('#'+ratio+" .y1").val(c.y);
$('#'+ratio+" .crop_width").val(c.w);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment