diff --git a/album-collage-generator.php b/album-collage-generator.php index 212f29e..e31847b 100644 --- a/album-collage-generator.php +++ b/album-collage-generator.php @@ -329,7 +329,11 @@ class AlbumCollageGenerator { $group_spacing = 50; for ($i = 0; $i < min(count($albums), 25); $i++) { - $album_text = $albums[$i]->author . ' - ' . $albums[$i]->album_name; + // Normalize album and author names to replace weird characters + $normalized_author = $this->normalize_text($albums[$i]->author); + $normalized_album = $this->normalize_text($albums[$i]->album_name); + $album_text = "{$normalized_author} - {$normalized_album}"; + $font = $this->is_japanese($album_text) ? $this->japanese_font : $this->western_font; $this->add_retro_text($image, $font_size, $text_x, $text_y, $text_color, $font, $album_text); @@ -351,6 +355,30 @@ class AlbumCollageGenerator { return $image_data; } + /** + * Normalize text by replacing accented or special characters with standard ones. + * + * @param string $text The input text to normalize. + * @return string The normalized text. + */ + private function normalize_text($text) { + // Check if the intl extension is loaded + if (class_exists('Transliterator')) { + $transliterator = \Transliterator::create('NFD; [:Nonspacing Mark:] Remove; NFC;'); + if ($transliterator) { + $text = $transliterator->transliterate($text); + } + } else { + // Fallback to iconv if intl is not available + $text = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $text); + } + + // Replace any remaining non-ASCII characters + $text = preg_replace('/[^\x20-\x7E]/', '', $text); + + return $text; + } + private function apply_retro_effects(&$image) { // Add noise $this->add_noise($image, 20); @@ -526,4 +554,4 @@ class AlbumCollageGenerator { } -new AlbumCollageGenerator(); +new AlbumCollageGenerator(); \ No newline at end of file