add canvas example

This commit is contained in:
Martin
2017-08-06 03:39:49 +02:00
parent 325ec84048
commit 868e9eae6c
2 changed files with 59 additions and 0 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

+59
View File
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<body>
<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>
<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 frame = document.getElementById('frame');
var editor = new ImageEditor('image-editor', {
type: 'canvas'
});
function cropImage() {
editor.crop(width.value, height.value);
}
function setFrame() {
editor.canvas.getViewport().setFrame(frame.value);
}
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});
}
}
//add event listeners
width.addEventListener('keyup', cropImage);
height.addEventListener('keyup', cropImage);
frame.addEventListener('change', setFrame);
window.addEventListener('resize', resizeEditor);
//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();
});
</script>
</body>
</html>