Changed around line 1
+ const logoUpload = document.getElementById('logo-upload');
+ const canvas = document.getElementById('logo-canvas');
+ const ctx = canvas.getContext('2d');
+ const overlay = document.getElementById('overlay');
+ const drawBoxBtn = document.getElementById('draw-box-btn');
+ const clearBoxBtn = document.getElementById('clear-box-btn');
+ const analyzeBtn = document.getElementById('analyze-btn');
+ const resultSection = document.getElementById('result');
+ const ratioValue = document.getElementById('ratio-value');
+ const passFail = document.getElementById('pass-fail');
+
+ let isDrawing = false;
+ let startX, startY, endX, endY;
+
+ logoUpload.addEventListener('change', (e) => {
+ const file = e.target.files[0];
+ if (file) {
+ const reader = new FileReader();
+ reader.onload = (event) => {
+ const img = new Image();
+ img.src = event.target.result;
+ img.onload = () => {
+ canvas.width = img.width;
+ canvas.height = img.height;
+ ctx.drawImage(img, 0, 0);
+ document.getElementById('analysis-section').classList.remove('hidden');
+ };
+ };
+ reader.readAsDataURL(file);
+ }
+ });
+
+ drawBoxBtn.addEventListener('click', () => {
+ isDrawing = true;
+ canvas.style.cursor = 'crosshair';
+ clearBoxBtn.classList.remove('hidden');
+ });
+
+ clearBoxBtn.addEventListener('click', () => {
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+ const img = new Image();
+ img.src = canvas.toDataURL();
+ img.onload = () => {
+ ctx.drawImage(img, 0, 0);
+ };
+ clearBoxBtn.classList.add('hidden');
+ });
+
+ canvas.addEventListener('mousedown', (e) => {
+ if (isDrawing) {
+ startX = e.offsetX;
+ startY = e.offsetY;
+ }
+ });
+
+ canvas.addEventListener('mouseup', (e) => {
+ if (isDrawing) {
+ endX = e.offsetX;
+ endY = e.offsetY;
+ drawBox();
+ isDrawing = false;
+ canvas.style.cursor = 'default';
+ }
+ });
+
+ function drawBox() {
+ ctx.strokeStyle = '#FF0000';
+ ctx.lineWidth = 2;
+ ctx.strokeRect(startX, startY, endX - startX, endY - startY);
+ }
+
+ analyzeBtn.addEventListener('click', () => {
+ const width = Math.abs(endX - startX);
+ const height = Math.abs(endY - startY);
+ const ratio = width / height;
+ const goldenRatio = 1.618;
+ const margin = 0.01;
+
+ ratioValue.textContent = ratio.toFixed(3);
+ resultSection.classList.remove('hidden');
+
+ if (Math.abs(ratio - goldenRatio) <= margin) {
+ passFail.textContent = 'PASS';
+ passFail.classList.remove('fail');
+ passFail.classList.add('pass');
+ } else {
+ passFail.textContent = 'FAIL';
+ passFail.classList.remove('pass');
+ passFail.classList.add('fail');
+ }
+ });