ImageGrid/Viewer/experiments/image-crop-edit.html
Alex A. Naanou 5f47d6da7b restructured the repo moving the legacy out of the way...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2020-08-28 17:32:02 +03:00

238 lines
4.1 KiB
HTML
Executable File

<!DOCTYPE html>
<html>
<style>
label {
margin: 0.2em;
}
label label {
margin: auto;
}
button {
border: none;
background: transparent;
}
input[type=checkbox],
input[type=radio] {
display: none;
}
input:not(:checked) ~ * {
opacity: 0.3;
}
input:hover:not(:checked) ~ * {
opacity: 0.8;
}
input:not(:checked) ~ sub:hover,
input:not(:checked) ~ sub {
opacity: 0.3;
}
.material-icons {
font-size: 2em;
}
sub .material-icons {
font-size: 1.5em;
}
.crop {
position: absolute;
width: 500px;
height: 500px;
border: solid 1px black;
}
.center {
position: relative;
top: 50%;
left: 50%;
width: 15px;
height: 15px;
margin-left: -8.5px;
margin-top: -8.5px;
border: solid 1px black;
border-radius: 50%;
}
.center:before {
display: block;
position: absolute;
content: "";
bottom: 50%;
right: 50%;
width: 15px;
height: 15px;
margin-right: -0.5px;
margin-bottom: -0.5px;
border-bottom: solid 1px black;
border-right: solid 1px black;
}
.center:after {
display: block;
position: absolute;
content: "";
top: 50%;
left: 50%;
width: 15px;
height: 15px;
margin-top: -0.5px;
margin-left: -0.5px;
border-top: solid 1px black;
border-left: solid 1px black;
}
</style>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="../css/fonts.css">
<script src="../ext-lib/jquery.js"></script>
<script src="../ext-lib/jquery-ui.js"></script>
<script src="../ext-lib/jquery.ui.touch-punch.min.js"></script>
<script src="../lib/jli.js"></script>
<script>
var ORIGINAL = 1
$(function(){
$('.crop')
.resizable({
handles: 'all',
})
.draggable()
$('.crop .center')
.draggable()
})
function setRatio(ratio){
var crop = $('.crop')
crop
.resizable("option", "aspectRatio", ratio)
// XXX this feels like a hack but it works...
.data('uiResizable')._aspectRatio = ratio
if(ratio === false){
$('#lock-ratio')[0].checked = false
return
}
var w = crop.width()
var h = crop.height()
// resize...
var t = w + h
h = t / (ratio + 1)
w = t - h
crop
.height(h)
.width(w)
}
function flip(){
var crop = $('.crop')
var r = crop.resizable("option", "aspectRatio")
if(r > 0){
setRatio(1/r)
// no aspect ratio defined, just switch...
} else {
var w = crop.width()
var h = crop.height()
crop
.height(w)
.width(h)
}
}
function toggleLock(m){
var crop = $('.crop')
var r = m || crop.resizable("option", "aspectRatio")
if(r === false){
var w = crop.width()
var h = crop.height()
$('#lock-ratio')[0].checked = true
setRatio(w/h)
} else {
$('#lock-ratio')[0].checked = false
setRatio(false)
}
}
</script>
<body>
<button><span title="toggle crop on/off" class="material-icons">crop</span></button>
<label>
<input type="radio" name="ratio" checked onclick="setRatio(false)">
<span class="material-icons">crop_free</span>
<sub>
<label>
<input id="lock-ratio" type="checkbox" onclick="toggleLock()">
<span class="material-icons">lock</span>
</label>
</sub>
</label>
<label>
<input type="radio" name="ratio" onclick="setRatio(ORIGINAL)">
<span title="original ratio" class="material-icons">crop_original</span>
</label>
<label>
<input type="radio" name="ratio" onclick="setRatio(1)">
<span class="material-icons">crop_square</span>
<span>1:1</span>
</label>
<label>
<input type="radio" name="ratio" onclick="setRatio(3/2)">
<span class="material-icons">crop_3_2</span>
<span>3:2</span>
</label>
<label>
<input type="radio" name="ratio" onclick="setRatio(16/9)">
<span class="material-icons">crop_16_9</span>
<span>16:9</span>
</label>
<button onclick="flip()"><span class="material-icons">crop_rotate</span></button>
<button><span class="material-icons">clear</span></button>
<br>
<pre>
TODO:
- rotation and rotation handle
- touch
- multitouch
- center point
</pre>
<div class="container">
<div class="crop">
<div class="center">
</div>
</div>
</div>
</body>
</html>
<!-- vim:set sw=4 ts=4 : -->