The problem of automatically generating an avatar for a Chinese user name

Hello everyone, I ’m from China
I found a small problem with the user’s default avatar during use

nextcloud version: 25 to 28
System version:centos 7.9
webserver:nginx 1.16.1 ; php 8.0.28
Browser version:Firefox 121.0 、Google Chrome 120.0、Microsoft Edge 120.0、etc

The problem is this
When creating an account for a user
When entering a Chinese name
The avatar picture will look like this:
0715da8e4728c40c42611574392117d

No problem in english:
cf9ea24a3157990aa4e6d03f2f07b5b

I know it does n’t affect the experience
But I still want to solve it
Then the interface will be more beautiful
thank you all

Thanks for letting us know :+1:

Would you mind inserting the not working character here in the forum so we can copy it and try to reproduce locally?

I tried “丹尼尔” and the result looks a bit different but still broken :confused:

image

It’s indeed a tricky question how to make it work.

The implementation tries different ways to generate the avatar.

With image magick: server/lib/private/Avatar/Avatar.php at 86575c96e39e9cc31d9c257cae1a41b2bfe36755 · nextcloud/server · GitHub

Without image magick we fallback to gd: https://github.com/nextcloud/server/blob/86575c96e39e9cc31d9c257cae1a41b2bfe36755/lib/private/Avatar/Avatar.php#L174

Question: Is php-imagick installed and enabled on your server?

We are using Noto Sans - Google Fonts to generate the avatars.

This font indeed does not support Chinese characters. You could try to replace the font with Noto Sans Simplified Chinese - Google Fonts and see if that works.

It would be really nice to have a better solution sometime. I’m not so familiar with this topic, and therefore always happy about your input/ideas.

Imagick and GD let us use one Font. I didn’t see a way to specify multiple fonts.

I thought about merging the font files, but that’s not so easy according to https://www.reddit.com/r/fonts/comments/nvqxu0/is_there_a_completely_combined_noto_font/ and How to combine two or more fonts? · Issue #167 · notofonts/noto-fonts · GitHub.

Another approach could be to add Noto Sans SC too and then check if the display name contains Chinese character and then pick Noto Sans SC over regular (e.g. cjk - What's the complete range for Chinese characters in Unicode? - Stack Overflow)

There is a closed bug report that looks similar to your problem: Avatar.php Garbled code · Issue #25427 · nextcloud/server · GitHub. I assume it’s closed because it was a bit unspecific.

cc @jan @szaimen

It is true that this problem also occurs when I upgrade to version 24 from version 23. However, there is a way to fix it.

Before:

After:

The specific way to fix it is to upload the NotoSans font that supports Chinese. For example, core/fonts/NotoSansCJKtc-Light.ttf (https://drive.google.com/file/d/1TWJgVJhwVoW7DKu69e8zmvxshn7AyU_P/view), and then edit lib/private/Avatar/Avatar.php to replace it:

sed -i 's/NotoSans-Regular.ttf/NotoSansCJKtc-Light.ttf/' lib/private/Avatar/Avatar.php

However, this method is no longer applicable when I upgrade to version 25 or higher.

Hi,

Please upgrade to Nextcloud 26 or higher as soon as possible.
Everything below is end of life and not maintained anymore.

More technical details about the avatar generation and fonts: https://github.com/nextcloud/server/pull/25529

image

The following patch may make the avatar generation work: https://github.com/nextcloud/server/pull/42534

However, I don’t know if that’s already enough.

Thank you, you have given me hope of solving the problem.
It is possible that my installation method and environment are different, and I have not solved the problem. My environment is as follows:

nextcloud version: 28.0.0
System version:centos 7.9
webserver:nginx 1.16.1 ; php 8.0.28
Installation method:Community Manual installation with Archive
Browser version:Firefox 121.0 、Google Chrome 120.0、Microsoft Edge 120.0、etc

Of course, it is also possible that I misunderstand the content described in Fix non LGC glyphs in avatars and txt file previews by danxuliu · Pull Request #25529 · nextcloud/server · GitHub 1.

I wonder if there is a solution that directly points out the problem and provides a solution for my environment?

According to the provided link information, it seems that I need to recompile PHP to enable GD support for Raqm.
On the one hand, I cannot find the Raqm or libraqm extension package in PHP’s PECL.
On the other hand, after installing libraqm-devel and libraqm via yum, I recompiled PHP, but the avatar issue remains the same.

I don’t think you need to recompile libgd or php.
The part about libraqm is relevant for right-to-left languages.

Mind giving feat: generate avatars for display name with chinese characters by kesselb · Pull Request #42534 · nextcloud/server · GitHub a try?

1 Like