Ajustement pour une interface minimale
This commit is contained in:
@@ -28,6 +28,12 @@ body, html {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--back-color: black;
|
--back-color: black;
|
||||||
--main-color: white;
|
--main-color: white;
|
||||||
@@ -41,6 +47,17 @@ body, html {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body > *{
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#welcome-panel {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-family: 'lineal', sans-serif;
|
font-family: 'lineal', sans-serif;
|
||||||
font-weight: bolder;
|
font-weight: bolder;
|
||||||
@@ -48,8 +65,8 @@ h1 {
|
|||||||
|
|
||||||
#ui-canvas {
|
#ui-canvas {
|
||||||
display: block;
|
display: block;
|
||||||
|
max-width: calc(100vw - 30px);
|
||||||
|
max-height: calc(100vh - 30px);
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
max-width: 100vw;
|
|
||||||
max-height: 100vh;
|
|
||||||
}
|
}
|
||||||
@@ -9,12 +9,17 @@ async function updateFromForm(){
|
|||||||
|
|
||||||
let image = data.get("image")
|
let image = data.get("image")
|
||||||
if(image.size > 0){
|
if(image.size > 0){
|
||||||
|
if(UI_GLITCHER.currentImageFile != image){
|
||||||
await UI_GLITCHER.setImage(image)
|
await UI_GLITCHER.setImage(image)
|
||||||
UI_GLITCHER.clearGlitch()
|
UI_GLITCHER.clearGlitch()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
UI_GLITCHER.clearImage()
|
UI_GLITCHER.clearImage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.getElementById("welcome-panel").hidden = image.size > 0
|
||||||
|
document.getElementById("glitch-panel").hidden = image.size == 0
|
||||||
|
|
||||||
UI_GLITCHER.render()
|
UI_GLITCHER.render()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +32,21 @@ FORM.addEventListener("submit", e => {
|
|||||||
updateFromForm()
|
updateFromForm()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
FORM.addEventListener("reset", e => {
|
||||||
|
FORM.elements["image"].value = ""
|
||||||
|
updateFromForm()
|
||||||
|
})
|
||||||
|
|
||||||
|
document.getElementById("download-btn").addEventListener("click", async e => {
|
||||||
|
e.preventDefault();
|
||||||
|
let data = await UI_GLITCHER.toBlob("image/jpeg", 0.9);
|
||||||
|
let a = document.createElement('a')
|
||||||
|
a.href = URL.createObjectURL(data)
|
||||||
|
a.download = UI_GLITCHER.currentImageFile.name
|
||||||
|
a.click()
|
||||||
|
setTimeout(() => URL.revokeObjectURL(a.href), 10000)
|
||||||
|
})
|
||||||
|
|
||||||
CANVAS.addEventListener("pointerdown", e => {
|
CANVAS.addEventListener("pointerdown", e => {
|
||||||
let pointerId = e.pointerId;
|
let pointerId = e.pointerId;
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,12 @@
|
|||||||
|
|
||||||
<input type="file" name="image" accept="image/jpg, image/jpeg,image/png,image/webp" />
|
<input type="file" name="image" accept="image/jpg, image/jpeg,image/png,image/webp" />
|
||||||
</div>
|
</div>
|
||||||
<div id="glitch-panel">
|
<div id="glitch-panel" hidden>
|
||||||
<canvas id="ui-canvas"></canvas>
|
<canvas id="ui-canvas"></canvas>
|
||||||
|
<nav>
|
||||||
|
<button type="reset">Reset</button>
|
||||||
|
<button type="button" id="download-btn">Télécharger</button>
|
||||||
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@@ -221,7 +221,23 @@ export class Glitcher {
|
|||||||
this.ctx.texParameteri(this.ctx.TEXTURE_2D, this.ctx.TEXTURE_MIN_FILTER, this.ctx.LINEAR);
|
this.ctx.texParameteri(this.ctx.TEXTURE_2D, this.ctx.TEXTURE_MIN_FILTER, this.ctx.LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
resize(width, height){
|
async toBlob(type, quality) {
|
||||||
|
this.resize(this.currentImage.width, this.currentImage.height, true)
|
||||||
|
this.render()
|
||||||
|
let blob = await new Promise((res, rej) => this.canvas.toBlob((imageBlob) => {
|
||||||
|
if(imageBlob){
|
||||||
|
res(imageBlob)
|
||||||
|
} else {
|
||||||
|
rej()
|
||||||
|
}
|
||||||
|
}, type, quality))
|
||||||
|
this.resize(this.currentImage.width, this.currentImage.height, false)
|
||||||
|
return blob
|
||||||
|
}
|
||||||
|
|
||||||
|
resize(width, height, force=false){
|
||||||
|
if(!force){
|
||||||
|
|
||||||
let computedStyle = window.getComputedStyle(this.canvas)
|
let computedStyle = window.getComputedStyle(this.canvas)
|
||||||
let maxWidth = parseFloat(computedStyle["max-width"])
|
let maxWidth = parseFloat(computedStyle["max-width"])
|
||||||
let maxHeight = parseFloat(computedStyle["max-height"])
|
let maxHeight = parseFloat(computedStyle["max-height"])
|
||||||
@@ -243,6 +259,12 @@ export class Glitcher {
|
|||||||
|
|
||||||
this.canvas.width = resize.width
|
this.canvas.width = resize.width
|
||||||
this.canvas.height = resize.height
|
this.canvas.height = resize.height
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.canvas.width = width
|
||||||
|
this.canvas.height = height
|
||||||
|
}
|
||||||
|
|
||||||
this.videoCanvas.width = this.canvas.width
|
this.videoCanvas.width = this.canvas.width
|
||||||
this.videoCanvas.height = this.canvas.height
|
this.videoCanvas.height = this.canvas.height
|
||||||
this.ctx.viewport(0, 0, this.canvas.width, this.canvas.height);
|
this.ctx.viewport(0, 0, this.canvas.width, this.canvas.height);
|
||||||
|
|||||||
Reference in New Issue
Block a user