Вырезаю crop'ом часть картинки.
Вот собсно каким образом:
<script type="text/javascript" src="jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="jquery.imgareaselect.pack.js"></script>
<script type="text/javascript">
function preview(img, selection) {
var scaleX = 240 / (selection.width || 1);
var scaleY = 480 / (selection.height || 1);
$('#photo + div > img').css({
width: Math.round(scaleX * 266) + 'px',
height: Math.round(scaleY * 604) + 'px',
marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
});
}
$(document).ready(function () {
$('<div><img src="777.jpg" style="position: relative;" /><div>') .css({
float: 'left',
position: 'relative',
overflow: 'hidden',
width: '240px',
height: '480px'
}) .insertAfter($('#photo'));
$('#photo').imgAreaSelect({
aspectRatio: '1:2',
handles: true,
onSelectChange: preview,
onSelectEnd: function ( image, selection ) {
$('input[name=x1]').val(selection.x1);
$('input[name=y1]').val(selection.y1);
$('input[name=x2]').val(selection.x2);
$('input[name=y2]').val(selection.y2);
$('input[name=w]').val(selection.width);
$('input[name=h]').val(selection.height);
}
});
});
</script>
aspectRatio отвечает за соотношение ширины к высоте вырезаемой картинки.
Вопрос: как дать возможность вырезать вариантный кусок например с отношением сторон от 1:1 до 1:2?
|