Skip to content

Instantly share code, notes, and snippets.

@dhilst dhilst/index.html
Created Apr 13, 2019

Embed
What would you like to do?
online photo filtering
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="author" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
</head>
<body>
<div>
<img id="image-id" src="/roupa.jpg">
</div>
<button onClick="reset()">Reset</button>
<div>
<label>Brightness
<input oninput="changeFilter('brightness', this)" type="range" min="-100" max="100" value="0" class="slider">
<span>0</span>
</label>
</div>
<div>
<label>Hue
<input oninput="changeFilter('hue', this)" type="range" min="0" max="100" value="0" class="slider">
<span>0</span>
</label>
</div>
<div>
<label>Noise
<input oninput="changeFilter('noise', this)" type="range" min="0" max="100" value="0" class="slider">
<span>0</span>
</label>
</div>
<div>
<label>Contrast
<input oninput="changeFilter('contrast', this)" type="range" min="-10" max="10" value="0" step="0.1" class="slider">
<span>0</span>
</label>
</div>
<div>
<label>Gamma
<input oninput="changeFilter('gamma', this)" type="range" min="0" max="5" value="0" step="0.01" class="slider">
<span>0</span>
</label>
</div>
<div>
<label>Saturation
<input oninput="changeFilter('saturation', this)" type="range" min="-100" max="100" value="0" class="slider">
<span>0</span>
</label>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/camanjs/4.1.2/caman.full.min.js"></script>
<script>
var filters = {};
var trottle = false;
function render() {
if (trottle) {
return;
}
trottle = true;
setTimeout(() => { trottle = false }, 10);
Caman("#image-id", function () {
this.revert(false);
Object.entries(filters).forEach(([filter, value]) => {
console.log('applying ', filter, value);
this[filter](parseFloat(value));
});
this.render();
});
};
function changeFilter(filter, target) {
filters[filter] = target.value;
$(target).siblings().text(target.value);
render();
}
function reset() {
$('.slider').val(0);
Caman("#image-id", function () {
this.revert();
});
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.