94 lines
3.6 KiB
HTML
94 lines
3.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<body>
|
|
|
|
<p>X: <span id="pos-x"></span></p>
|
|
<p>Y: <span id="pos-y"></span></p>
|
|
|
|
|
|
<label>Width:</label>
|
|
<input type="text" id="width" name="width" value="100" />
|
|
<label>Height:</label>
|
|
<input type="text" id="height" name="height" value="80" />
|
|
<label>Frame:</label>
|
|
<select id="frame">
|
|
<option value="none">None</option>
|
|
<option value="white">White</option>
|
|
<option value="black">Black</option>
|
|
<option value="image">Image</option>
|
|
</select>
|
|
<label>Unit:</label>
|
|
<select id="unit">
|
|
<option value="cm">Cm</option>
|
|
<option value="inch">Inches</option>
|
|
</select>
|
|
<canvas id="image-editor" width="800" height="600"></canvas>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.11/fabric.js"></script>
|
|
<script src="../../dist/image-editor.js"></script>
|
|
<script type="text/javascript">
|
|
var width = document.getElementById('width');
|
|
var height = document.getElementById('height');
|
|
var unit = document.getElementById('unit');
|
|
var frame = document.getElementById('frame');
|
|
var posX = document.getElementById('pos-x');
|
|
var posY = document.getElementById('pos-y');
|
|
|
|
var editor = new ImageEditor('image-editor', {
|
|
type: 'canvas',
|
|
isVisibleFullscreenButton: false
|
|
});
|
|
|
|
function cropImage() {
|
|
editor.crop(width.value, height.value, unit.value);
|
|
}
|
|
|
|
function setFrame() {
|
|
editor.canvas.getViewport().setFrame(frame.value);
|
|
}
|
|
|
|
function showCoordinates() {
|
|
var data = editor.canvas.getImageData().getData();
|
|
posX.innerText = data.x;
|
|
posY.innerText = data.y;
|
|
}
|
|
|
|
function resizeEditor() {
|
|
var isFullscreen = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement;
|
|
if(isFullscreen) {
|
|
editor.canvas.resize({width: window.innerWidth, height: window.innerHeight});
|
|
} else {
|
|
editor.canvas.resize({width: 800, height: 600});
|
|
}
|
|
}
|
|
|
|
function setUnit() {
|
|
if (unit.value == 'inch') {
|
|
width.value = Math.round(width.value / 2.54 * 100) / 100;
|
|
height.value = Math.round(height.value / 2.54 * 100) / 100;
|
|
} else {
|
|
width.value = Math.round(width.value * 2.54);
|
|
height.value = Math.round(height.value * 2.54);
|
|
}
|
|
cropImage();
|
|
}
|
|
|
|
//add event listeners
|
|
width.addEventListener('keyup', cropImage);
|
|
height.addEventListener('keyup', cropImage);
|
|
frame.addEventListener('change', setFrame);
|
|
unit.addEventListener('change', setUnit);
|
|
window.addEventListener('resize', resizeEditor);
|
|
$(document).on('PIE:dragged', showCoordinates);
|
|
|
|
//load the image (needs to be an remote image for 3D to work)
|
|
editor.loadImage('http://images.photowall.com/products/42229.jpg?h=450', function() {
|
|
cropImage();
|
|
showCoordinates();
|
|
});
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|