diff --git a/css/styles.css b/css/styles.css index 9bcc6c5..932b48e 100644 --- a/css/styles.css +++ b/css/styles.css @@ -90,6 +90,46 @@ label { font-weight: 600; } +.hr { + border: 0; + border-top: 1px solid #ccc; +} + +.form-grid { + display: grid; + grid-template-columns: 2fr 1fr; + gap: 10px 20px; + align-items: center; + max-width: 500px; + margin: auto; +} + +.form-grid label { + text-align: left; + font-weight: 600; +} + +.form-grid input[type="checkbox"] { + width: 20px; + height: 20px; + cursor: pointer; + justify-self: start; +} + +.form-grid input[type="color"] { + width: 100%; + height: 40px; + border: none; + cursor: pointer; +} + +.form-grid select { + width: 100%; + padding: 8px; + border-radius: 4px; + border: 1px solid #ccc; +} + textarea, input[type="file"], input[type="range"], input[type="checkbox"] { padding: 12px 16px; font-size: 16px; @@ -139,6 +179,7 @@ input[type="checkbox"] { .preview { flex: 1; display: flex; + flex-direction: column; align-items: center; padding: 20px; background-color: #fff; @@ -147,10 +188,25 @@ input[type="checkbox"] { } #canvas { - max-width: 100%; - max-height: 100%; + max-width: 90%; + max-height: 80vh; + width: 100%; + height: 100%; border: 1px solid #ddd; border-radius: 8px; + object-fit: contain; + flex: 1 1 auto; +} + +.canvas-hint { + margin-top: 10px; + font-size: 14px; + color: #666; + text-align: center; +} + +.canvas-hint p { + margin-bottom: 2px; } /* ======================== diff --git a/index.html b/index.html index ac76dd7..222d5db 100644 --- a/index.html +++ b/index.html @@ -49,30 +49,62 @@
- +
+
+

Hinweis: Du kannst das Hintergrundbild durch Ziehen mit der Maus oder

+

Wischen mit dem Finger frei verschieben!

+
- +
+
+ + +
+ +
+ -
- - +
+ +
+ + + + + + + +
+
+ - + - + + +
diff --git a/js/script.js b/js/script.js index b7b761f..9a99984 100644 --- a/js/script.js +++ b/js/script.js @@ -45,7 +45,9 @@ document.getElementById('subline').addEventListener('input', generateSharepic); document.getElementById('fontSize').addEventListener('input', generateSharepic); document.getElementById('boxHeight').addEventListener('input', generateSharepic); document.getElementById('logoSize').addEventListener('input', generateSharepic); -document.getElementById('logoLeft').addEventListener('change', generateSharepic); +document.getElementById('logoPosition').addEventListener('change', generateSharepic); +document.getElementById('logoBackground').addEventListener('change', generateSharepic); +document.getElementById('logoColor').addEventListener('input', drawCanvas); // Verarbeitet den Upload eines neuen Hintergrundbildes function handleImageUpload(event) { @@ -98,8 +100,17 @@ function drawCanvas() { const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); - canvas.width = 1080; - canvas.height = 1080; + const canvasSize = document.getElementById('canvasSize').value; + if (canvasSize === 'square') { + canvas.width = 1080; + canvas.height = 1080; + } else if (canvasSize === 'horizontal') { + canvas.width = 1080; + canvas.height = 1920; + } else if (canvasSize === 'vertical') { + canvas.width = 1920; + canvas.height = 1080; + } // Zeichnet das hochgeladene Hintergrundbild if (uploadedImage) { @@ -166,14 +177,85 @@ function drawCanvas() { logoHeight = logoWidth / logoRatio; } - const logoLeft = document.getElementById('logoLeft').checked; - const logoX = logoLeft ? 20 : canvas.width - logoWidth - 20; + const logoPosition = document.getElementById('logoPosition').value; + let logoX, logoY; - ctx.drawImage(uploadedLogo, logoX, 20, logoWidth, logoHeight); + switch (logoPosition) { + case 'top-left': + logoX = 20; + logoY = 20; + break; + case 'top-right': + logoX = canvas.width - logoWidth - 20; + logoY = 20; + break; + case 'bottom-left': + logoX = 20; + logoY = canvas.height - logoHeight - 20; + break; + case 'bottom-right': + logoX = canvas.width - logoWidth - 20; + logoY = canvas.height - logoHeight - 20; + break; + } + + // Erstellt ein temporäres Canvas für die Farbmanipulation + const tempCanvas = document.createElement('canvas'); + tempCanvas.width = logoWidth; + tempCanvas.height = logoHeight; + const tempCtx = tempCanvas.getContext('2d'); + + // Zeichnet das Original-Logo + tempCtx.drawImage(uploadedLogo, 0, 0, logoWidth, logoHeight); + + // Holt die ausgewählte Farbe + const logoColor = document.getElementById('logoColor').value; + + // Setzt den Modus auf "source-atop" und färbt das Logo um + tempCtx.globalCompositeOperation = 'source-atop'; + tempCtx.fillStyle = logoColor; + tempCtx.fillRect(0, 0, logoWidth, logoHeight); + + // Zeichnet den Hintergrund, falls aktiviert + const logoBackground = document.getElementById('logoBackground').checked; + if (logoBackground) { + ctx.fillStyle = '#ffffff'; + ctx.fillRect(logoX, logoY, logoWidth, logoHeight); + } + + // Zeichnet das eingefärbte Logo auf das Haupt-Canvas + ctx.drawImage(tempCanvas, logoX, logoY); } } // Canvas-Referenz +document.getElementById('canvasSize').addEventListener('change', function (e) { + const canvas = document.getElementById('canvas'); + const selectedSize = e.target.value; + + // Setze die Canvas-Größe basierend auf der Auswahl + switch (selectedSize) { + case 'square': + canvas.width = 1080; + canvas.height = 1080; + break; + case 'horizontal': + canvas.width = 1080; + canvas.height = 1920; + break; + case 'vertical': + canvas.width = 1920; + canvas.height = 1080; + break; + } + + // Setze die Offsets zurück, wenn die Canvas-Größe geändert wird + imageOffsetX = 0; + imageOffsetY = 0; + + drawCanvas(); +}); + const canvas = document.getElementById('canvas'); if (!canvas) { console.error('Canvas element not found');