Spaces:
Runtime error
Runtime error
Commit
·
e8ffae8
1
Parent(s):
7a85ee8
Update styling
Browse files- web/static/script.js +30 -7
- web/static/styles.css +1 -1
web/static/script.js
CHANGED
|
@@ -44,15 +44,38 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
| 44 |
uploadedImage.classList.add("uploaded-image");
|
| 45 |
uploadedImage.onload = async () => {
|
| 46 |
|
| 47 |
-
|
| 48 |
const imageHeight = uploadedImage.height;
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
const
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
dropzone.innerHTML = "";
|
| 55 |
-
dropzone.appendChild(
|
| 56 |
};
|
| 57 |
};
|
| 58 |
|
|
|
|
| 44 |
uploadedImage.classList.add("uploaded-image");
|
| 45 |
uploadedImage.onload = async () => {
|
| 46 |
|
| 47 |
+
const imageWidth = uploadedImage.width;
|
| 48 |
const imageHeight = uploadedImage.height;
|
| 49 |
+
|
| 50 |
+
// Create a canvas to draw cropped image
|
| 51 |
+
const canvas = document.createElement("canvas");
|
| 52 |
+
const ctx = canvas.getContext("2d");
|
| 53 |
+
canvas.width = 225;
|
| 54 |
+
canvas.height = 225;
|
| 55 |
+
|
| 56 |
+
let sourceX, sourceY, sourceWidth, sourceHeight;
|
| 57 |
+
|
| 58 |
+
if (imageWidth > imageHeight) {
|
| 59 |
+
// Image is wider than it is tall
|
| 60 |
+
sourceHeight = imageHeight;
|
| 61 |
+
sourceWidth = imageHeight;
|
| 62 |
+
sourceX = (imageWidth - sourceWidth) / 2;
|
| 63 |
+
sourceY = 0;
|
| 64 |
+
} else {
|
| 65 |
+
// Image is taller than it is wide or square
|
| 66 |
+
sourceWidth = imageWidth;
|
| 67 |
+
sourceHeight = imageWidth;
|
| 68 |
+
sourceY = (imageHeight - sourceHeight) / 2;
|
| 69 |
+
sourceX = 0;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
ctx.drawImage(uploadedImage, sourceX, sourceY, sourceWidth, sourceHeight, 0, 0, 225, 225);
|
| 73 |
+
|
| 74 |
+
const croppedImage = new Image();
|
| 75 |
+
croppedImage.src = canvas.toDataURL();
|
| 76 |
+
croppedImage.classList.add("uploaded-image");
|
| 77 |
dropzone.innerHTML = "";
|
| 78 |
+
dropzone.appendChild(croppedImage);
|
| 79 |
};
|
| 80 |
};
|
| 81 |
|
web/static/styles.css
CHANGED
|
@@ -3,7 +3,7 @@ body {
|
|
| 3 |
margin-top: 40px;
|
| 4 |
margin-left: 10px;
|
| 5 |
margin-right: 10px;
|
| 6 |
-
margin-bottom:
|
| 7 |
padding: 0;
|
| 8 |
text-align: center;
|
| 9 |
}
|
|
|
|
| 3 |
margin-top: 40px;
|
| 4 |
margin-left: 10px;
|
| 5 |
margin-right: 10px;
|
| 6 |
+
margin-bottom: 400px;
|
| 7 |
padding: 0;
|
| 8 |
text-align: center;
|
| 9 |
}
|