1
0

added normalization of titles since font doesnt support it lol

This commit is contained in:
anon 2024-10-19 12:52:13 +00:00
parent d00edefc95
commit 55e0ad611c

View File

@ -329,7 +329,11 @@ class AlbumCollageGenerator {
$group_spacing = 50; $group_spacing = 50;
for ($i = 0; $i < min(count($albums), 25); $i++) { 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; $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); $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; 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) { private function apply_retro_effects(&$image) {
// Add noise // Add noise
$this->add_noise($image, 20); $this->add_noise($image, 20);
@ -526,4 +554,4 @@ class AlbumCollageGenerator {
} }
new AlbumCollageGenerator(); new AlbumCollageGenerator();