undo and redo adding new cropper library as it had a .git config from the original project

This commit is contained in:
zotlabs
2018-01-23 16:42:24 -08:00
parent 1e8dcaffc9
commit 5902528bae
121 changed files with 34733 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Cropper.js</title>
<link rel="stylesheet" href="../dist/cropper.css">
<style>
.container {
max-width: 640px;
margin: 20px auto;
}
img {
max-width: 100%;
}
</style>
</head>
<body>
<div class="container">
<h1>Cropper with a range of aspect ratio</h1>
<div>
<img id="image" src="../docs/images/picture.jpg" alt="Picture">
</div>
</div>
<script src="../dist/cropper.js"></script>
<script>
window.addEventListener('DOMContentLoaded', function () {
var image = document.querySelector('#image');
var minAspectRatio = 0.5;
var maxAspectRatio = 1.5;
var cropper = new Cropper(image, {
ready: function () {
var cropper = this.cropper;
var containerData = cropper.getContainerData();
var cropBoxData = cropper.getCropBoxData();
var aspectRatio = cropBoxData.width / cropBoxData.height;
var newCropBoxWidth;
if (aspectRatio < minAspectRatio || aspectRatio > maxAspectRatio) {
newCropBoxWidth = cropBoxData.height * ((minAspectRatio + maxAspectRatio) / 2);
cropper.setCropBoxData({
left: (containerData.width - newCropBoxWidth) / 2,
width: newCropBoxWidth
});
}
},
cropmove: function () {
var cropper = this.cropper;
var cropBoxData = cropper.getCropBoxData();
var aspectRatio = cropBoxData.width / cropBoxData.height;
if (aspectRatio < minAspectRatio) {
cropper.setCropBoxData({
width: cropBoxData.height * minAspectRatio
});
} else if (aspectRatio > maxAspectRatio) {
cropper.setCropBoxData({
width: cropBoxData.height * maxAspectRatio
});
}
}
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,103 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Cropper.js</title>
<link rel="stylesheet" href="../dist/cropper.css">
<style>
.container {
max-width: 640px;
margin: 20px auto;
}
img {
max-width: 100%;
}
.cropper-view-box,
.cropper-face {
border-radius: 50%;
}
</style>
</head>
<body>
<div class="container">
<h1>Crop a round image</h1>
<h3>Image</h3>
<div>
<img id="image" src="../docs/images/picture.jpg" alt="Picture">
</div>
<h3>Result</h3>
<p>
<button type="button" id="button">Crop</button>
</p>
<div id="result"></div>
</div>
<script src="../dist/cropper.js"></script>
<script>
(function () {
function getRoundedCanvas(sourceCanvas) {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var width = sourceCanvas.width;
var height = sourceCanvas.height;
canvas.width = width;
canvas.height = height;
context.imageSmoothingEnabled = true;
context.drawImage(sourceCanvas, 0, 0, width, height);
context.globalCompositeOperation = 'destination-in';
context.beginPath();
context.arc(width / 2, height / 2, Math.min(width, height) / 2, 0, 2 * Math.PI, true);
context.fill();
return canvas;
}
window.addEventListener('DOMContentLoaded', function () {
var image = document.getElementById('image');
var button = document.getElementById('button');
var result = document.getElementById('result');
var croppable = false;
var cropper = new Cropper(image, {
aspectRatio: 1,
viewMode: 1,
ready: function () {
croppable = true;
}
});
button.onclick = function () {
var croppedCanvas;
var roundedCanvas;
var roundedImage;
if (!croppable) {
return;
}
// Crop
croppedCanvas = cropper.getCroppedCanvas();
// Round
roundedCanvas = getRoundedCanvas(croppedCanvas);
// Show
roundedImage = document.createElement('img');
roundedImage.src = roundedCanvas.toDataURL()
result.innerHTML = '';
result.appendChild(roundedImage);
};
});
})();
</script>
</body>
</html>

View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Cropper.js</title>
<link rel="stylesheet" href="../dist/cropper.css">
<style>
.container {
max-width: 640px;
margin: 20px auto;
}
img {
max-width: 100%;
}
</style>
</head>
<body>
<div class="container">
<h1>Crop a cross origin image</h1>
<p>A cross origin image with a <code>crossorigin</code> attribute and an available <code>Access-Control-Allow-Origin</code> response header can be cropped by Cropper.</p>
<h3>Image</h3>
<div>
<img id="image" src="https://raw.githubusercontent.com/fengyuanchen/cropperjs/master/docs/images/picture.jpg" crossorigin>
</div>
<h3>Result</h3>
<div id="result"></div>
</div>
<script src="../dist/cropper.js"></script>
<script>
window.addEventListener('DOMContentLoaded', function () {
var image = document.querySelector('#image');
var result = document.querySelector('#result');
var cropper = new Cropper(image, {
ready: function () {
var image = new Image();
image.src = cropper.getCroppedCanvas().toDataURL('image/jpeg');
result.appendChild(image);
},
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Cropper.js</title>
<link rel="stylesheet" href="../dist/cropper.css">
<style>
.container {
max-width: 640px;
margin: 20px auto;
}
img {
max-width: 100%;
}
</style>
</head>
<body>
<div class="container">
<h1>Crop on canvas with Cropper</h1>
<h3>Image</h3>
<div class="img-container">
<img id="image" src="../docs/images/picture.jpg" alt="Picture">
</div>
<h3>Canvas</h3>
<div class="img-container">
<canvas id="canvas"></canvas>
</div>
</div>
<script src="../dist/cropper.js"></script>
<script>
function start() {
var width = this.offsetWidth;
var height = this.offsetHeight;
var cropper;
canvas.width = width;
canvas.height = height;
canvas.getContext('2d').drawImage(
this,
0, 0, this.naturalWidth, this.naturalHeight,
0, 0, width, height
);
cropper = new Cropper(canvas);
}
window.addEventListener('DOMContentLoaded', function () {
var canvas = document.getElementById('canvas');
var image = document.getElementById('image');
if (image.complete) {
start.call(image);
} else {
image.onload = start;
}
});
</script>
</body>
</html>

View File

@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Cropper.js</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<link rel="stylesheet" href="../dist/cropper.css">
<style>
.img-container img {
max-width: 100%;
}
</style>
</head>
<body>
<div class="container">
<h1>Cropper in a Bootstrap modal</h1>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-target="#modal" data-toggle="modal">
Launch the demo
</button>
<!-- Modal -->
<div class="modal fade" id="modal" role="dialog" aria-labelledby="modalLabel" tabindex="-1">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalLabel">Cropper</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="img-container">
<img id="image" src="../docs/images/picture.jpg" alt="Picture">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="../dist/cropper.js"></script>
<script>
window.addEventListener('DOMContentLoaded', function () {
var image = document.getElementById('image');
var cropBoxData;
var canvasData;
var cropper;
$('#modal').on('shown.bs.modal', function () {
cropper = new Cropper(image, {
autoCropArea: 0.5,
ready: function () {
// Strict mode: set crop box data first
cropper.setCropBoxData(cropBoxData).setCanvasData(canvasData);
}
});
}).on('hidden.bs.modal', function () {
cropBoxData = cropper.getCropBoxData();
canvasData = cropper.getCanvasData();
cropper.destroy();
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,123 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Cropper.js</title>
<link rel="stylesheet" href="../dist/cropper.css">
<style>
.container {
max-width: 960px;
margin: 20px auto;
}
img {
max-width: 100%;
}
.row,
.preview {
overflow: hidden;
}
.col {
float: left;
}
.col-6 {
width: 50%;
}
.col-3 {
width: 25%;
}
.col-2 {
width: 16.7%;
}
.col-1 {
width: 8.3%;
}
</style>
</head>
<body>
<div class="container">
<h1>Customize preview for Cropper</h1>
<div class="row">
<div class="col col-6">
<img id="image" src="../docs/images/picture.jpg" alt="Picture">
</div>
<div class="col col-3">
<div class="preview"></div>
</div>
<div class="col col-2">
<div class="preview"></div>
</div>
<div class="col col-1">
<div class="preview"></div>
</div>
</div>
</div>
<script src="../dist/cropper.js"></script>
<script>
function each(arr, callback) {
var length = arr.length;
var i;
for (i = 0; i < length; i++) {
callback.call(arr, arr[i], i, arr);
}
return arr;
}
window.addEventListener('DOMContentLoaded', function () {
var image = document.querySelector('#image');
var previews = document.querySelectorAll('.preview');
var cropper = new Cropper(image, {
ready: function () {
var clone = this.cloneNode();
clone.className = ''
clone.style.cssText = (
'display: block;' +
'width: 100%;' +
'min-width: 0;' +
'min-height: 0;' +
'max-width: none;' +
'max-height: none;'
);
each(previews, function (elem) {
elem.appendChild(clone.cloneNode());
});
},
crop: function (e) {
var data = e.detail;
var cropper = this.cropper;
var imageData = cropper.getImageData();
var previewAspectRatio = data.width / data.height;
each(previews, function (elem) {
var previewImage = elem.getElementsByTagName('img').item(0);
var previewWidth = elem.offsetWidth;
var previewHeight = previewWidth / previewAspectRatio;
var imageScaledRatio = data.width / previewWidth;
elem.style.height = previewHeight + 'px';
previewImage.style.width = imageData.naturalWidth / imageScaledRatio + 'px';
previewImage.style.height = imageData.naturalHeight / imageScaledRatio + 'px';
previewImage.style.marginLeft = -data.x / imageScaledRatio + 'px';
previewImage.style.marginTop = -data.y / imageScaledRatio + 'px';
});
}
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Cropper.js</title>
<link rel="stylesheet" href="../dist/cropper.css">
<style>
.container {
max-width: 640px;
margin: 20px auto;
}
img {
max-width: 100%;
}
</style>
</head>
<body>
<div class="container">
<h1>Cropper with fixed crop box</h1>
<div>
<img id="image" src="../docs/images/picture.jpg" alt="Picture">
</div>
</div>
<script src="../dist/cropper.js"></script>
<script>
window.addEventListener('DOMContentLoaded', function () {
var image = document.querySelector('#image');
var cropper = new Cropper(image, {
dragMode: 'move',
aspectRatio: 16 / 9,
autoCropArea: 0.65,
restore: false,
guides: false,
center: false,
highlight: false,
cropBoxMovable: false,
cropBoxResizable: false,
toggleDragModeOnDblclick: false,
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Cropper.js</title>
<link rel="stylesheet" href="../dist/cropper.css">
<style>
.container {
max-width: 640px;
margin: 20px auto;
}
img {
max-width: 100%;
}
</style>
</head>
<body>
<div class="container">
<h1>Cropper with full crop box</h1>
<div>
<img id="image" src="../docs/images/picture.jpg" alt="Picture">
</div>
</div>
<script src="../dist/cropper.js"></script>
<script>
window.addEventListener('DOMContentLoaded', function () {
var image = document.querySelector('#image');
var cropper = new Cropper(image, {
viewMode: 3,
dragMode: 'move',
autoCropArea: 1,
restore: false,
modal: false,
guides: false,
highlight: false,
cropBoxMovable: false,
cropBoxResizable: false,
toggleDragModeOnDblclick: false,
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,123 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Cropper.js</title>
<link rel="stylesheet" href="../dist/cropper.css">
<style>
.container {
max-width: 640px;
margin: 20px auto;
}
img {
max-width: 100%;
}
.cropper-view-box,
.cropper-face {
background-color: black;
opacity: 1;
}
</style>
</head>
<body>
<div class="container">
<h1>Mask an image (Redaction)</h1>
<h3>Image</h3>
<div>
<img id="image" src="../docs/images/picture.jpg" alt="Picture">
</div>
<h3>Result</h3>
<p><button type="button" id="button">Mask</button></p>
<div id="result"></div>
</div>
<script src="../dist/cropper.js"></script>
<script>
(function () {
function getMaskedCanvas(sourceCanvas, sourceImage, cropper) {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var maskWidth = cropper.getData().width;
var maskHeight = cropper.getData().height;
var maskTop = cropper.getData().y;
var maskLeft = cropper.getData().x;
var imageWidth = cropper.getImageData().naturalWidth;
var imageHeight = cropper.getImageData().naturalHeight;
var imageLeft = cropper.getImageData().left;
var imageTop = cropper.getImageData().top;
var imageAspect = cropper.getImageData().aspectRatio;
canvas.width = imageWidth;
canvas.height = imageHeight;
// debug
console.log('Image Width: ' + imageWidth + ' Image Height: ' + imageHeight + ' Image Aspect Ratio: ' + imageAspect );
console.log('Image Left: ' + imageLeft + ' Image Top: ' + imageTop );
console.log('Mask Width: ' + maskWidth + ' Mask Height: ' + maskHeight + ' Mask Left: ' + maskLeft + ' Mask Top: ' + maskTop);
context.imageSmoothingEnabled = true;
context.drawImage(image, 0, 0, imageWidth, imageHeight);
context.fillRect(maskLeft, maskTop, maskWidth, maskHeight);
return canvas;
}
window.addEventListener('DOMContentLoaded', function () {
var image = document.getElementById('image');
var button = document.getElementById('button');
var result = document.getElementById('result');
var croppable = false;
var cropper = new Cropper(image, {
viewMode: 0,
guides: true,
center: true,
highlight: true,
cropBoxMovable: true,
cropBoxResizable: true,
ready: function () {
croppable = true;
}
});
button.onclick = function () {
var croppedCanvas;
var roundedCanvas;
var roundedImage;
if (!croppable) {
return;
}
// Crop
croppedCanvas = cropper.getCroppedCanvas();
// Mask
maskedCanvas = getMaskedCanvas(croppedCanvas, image, cropper);
// Show
maskedImage = document.createElement('img');
maskedImage.src = maskedCanvas.toDataURL()
result.innerHTML = '';
result.appendChild(maskedImage);
};
});
})();
</script>
</body>
</html>

View File

@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Cropper.js</title>
<link rel="stylesheet" href="../dist/cropper.css">
<style>
.container {
max-width: 640px;
margin: 20px auto;
}
img {
max-width: 100%;
}
</style>
</head>
<body>
<div class="container">
<h1>Multiple Croppers</h1>
<h3>Cropper</h3>
<div>
<img src="../docs/images/picture.jpg" alt="Picture">
</div>
<h3>Another</h3>
<div>
<img src="../docs/images/picture.jpg" alt="Picture">
</div>
</div>
<script src="../dist/cropper.js"></script>
<script>
window.addEventListener('DOMContentLoaded', function () {
var images = document.querySelectorAll('img');
var length = images.length;
var croppers = [];
var i;
for (i = 0; i < length; i++) {
croppers.push(new Cropper(images[i]));
}
});
</script>
</body>
</html>

View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Cropper.js</title>
<link rel="stylesheet" href="../dist/cropper.css">
<style>
.container {
max-width: 640px;
margin: 20px auto;
}
img {
width: 100%;
}
</style>
</head>
<body>
<div class="container">
<h1>Cropper with responsive container</h1>
<p>
<button type="button" id="replace">Replace Image</button>
</p>
<div>
<img id="image" src="../docs/images/picture.jpg" alt="Picture">
</div>
</div>
<script src="../dist/cropper.js"></script>
<script>
window.addEventListener('DOMContentLoaded', function () {
var image = document.querySelector('#image');
var cropper = new Cropper(image, {
movable: false,
zoomable: false,
rotatable: false,
scalable: false
});
document.getElementById('replace').onclick = function () {
cropper.replace('../docs/images/picture-2.jpg');
};
});
</script>
</body>
</html>