From be565201b0acda7858f4fd71325348d34df7c158 Mon Sep 17 00:00:00 2001 From: "Kreinsen, Moritz" <moritz.kreinsen@uni-hamburg.de> Date: Sun, 12 Mar 2023 19:48:03 +0000 Subject: [PATCH] Update index.php --- index.php | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 189acd6..596a5c4 100644 --- a/index.php +++ b/index.php @@ -11,7 +11,41 @@ <body> <section class="memory-game"> <div class="memory-card" data-framework="A"> - <?php $text = 'A'; $style = 'background-color: #FFCCCB'; $width = 640 * 0.25 - 10; $height = 640 * 0.33333 - 10; $textSize = min($width, $height) * 0.4; $svg = "<svg xmlns='http://www.w3.org/2000/svg' width='$width' height='$height'><text x='50%' y='50%' text-anchor='middle' alignment-baseline='middle' font-size='$textSize'>$text</text></svg>"; $svgData = base64_encode($svg); $src = 'data:image/svg+xml;base64,'.$svgData; $imgTag = "<img class='front-face' src='$src' alt='$text' style='$style'/>"; echo $imgTag; ?> + <?php + $text = 'Dies ist ein Testtext!'; + $style = 'background-color: #FFCCCB'; + $width = 640 * 0.25 - 10; + $height = 640 * 0.33333 - 10; + $textSize = min($width, $height) * 0.4; + + // Text in mehrere Zeilen aufteilen + $words = explode(' ', $text); + $lines = array(''); + $currentLine = 0; + foreach ($words as $word) { + $testLine = $lines[$currentLine] . ' ' . $word; + $testWidth = $textSize * strlen($testLine) / 2; + if ($testWidth > $width * 0.9) { // 90% der Breite für Zeilenumbruch verwenden + $currentLine++; + $lines[$currentLine] = $word; + } else { + $lines[$currentLine] = $testLine; + } + } + $text = implode("\n", $lines); + + // SVG-Code generieren + $svg = "<svg xmlns='http://www.w3.org/2000/svg' width='$width' height='$height'>"; + $svg .= "<text x='50%' y='50%' text-anchor='middle' alignment-baseline='middle' font-size='$textSize'>"; + $svg .= $text; + $svg .= "</text></svg>"; + + $svgData = base64_encode($svg); + $src = 'data:image/svg+xml;base64,'.$svgData; + $imgTag = "<img class='front-face' src='$src' alt='$text' style='$style'/>"; + echo $imgTag; + ?> + <!-- <img class="front-face" src="img/aurelia.svg" alt="Aurelia" style="background-color: #FFCCCB"/> --> <!-- <img class="back-face" src="img/js-badge.svg" alt="" /> --> <?php echo $backface; ?> -- GitLab