|
@@ -2,6 +2,7 @@ package cn.tr.core.utils;
|
|
|
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.util.Base64Utils;
|
|
import org.springframework.util.Base64Utils;
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
import javax.imageio.ImageIO;
|
|
@@ -22,9 +23,27 @@ import java.util.regex.Pattern;
|
|
|
* @Author : LF
|
|
* @Author : LF
|
|
|
* @Date: 2023年09月04日
|
|
* @Date: 2023年09月04日
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
|
|
+@Slf4j
|
|
|
public class AvatarUtil {
|
|
public class AvatarUtil {
|
|
|
private volatile static Map<String, String> avatarMap=new WeakHashMap<>();
|
|
private volatile static Map<String, String> avatarMap=new WeakHashMap<>();
|
|
|
|
|
+ private static Font singleWordFont;
|
|
|
|
|
+
|
|
|
|
|
+ static {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //小米字体MiSans-Medium
|
|
|
|
|
+ singleWordFont = Font.createFont(Font.TRUETYPE_FONT, AvatarUtil.class.getClassLoader().getResourceAsStream("avatarFont.ttf")).deriveFont(Font.PLAIN, 50);
|
|
|
|
|
+ } catch (FontFormatException e) {
|
|
|
|
|
+ log.error("字体加载失败",e);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ static {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
/**
|
|
/**
|
|
|
* 圆角大小
|
|
* 圆角大小
|
|
|
*/
|
|
*/
|
|
@@ -107,14 +126,14 @@ public class AvatarUtil {
|
|
|
if(nameWritten.length() ==1) {
|
|
if(nameWritten.length() ==1) {
|
|
|
// 中文
|
|
// 中文
|
|
|
if(isChinese(nameWritten)) {
|
|
if(isChinese(nameWritten)) {
|
|
|
- font = new Font("华文中宋", Font.PLAIN, 50);
|
|
|
|
|
- g2.setFont(font);
|
|
|
|
|
- g2.drawString(nameWritten, 25, 65);
|
|
|
|
|
|
|
+// font = new Font("华文中宋", Font.PLAIN, 50);
|
|
|
|
|
+ g2.setFont(singleWordFont);
|
|
|
|
|
+ g2.drawString(nameWritten, 25, 67);
|
|
|
}
|
|
}
|
|
|
// 英文
|
|
// 英文
|
|
|
else {
|
|
else {
|
|
|
- font = new Font("华文中宋", Font.PLAIN, 55);
|
|
|
|
|
- g2.setFont(font);
|
|
|
|
|
|
|
+// font = new Font("华文中宋", Font.PLAIN, 55);
|
|
|
|
|
+ g2.setFont(singleWordFont);
|
|
|
g2.drawString(nameWritten.toUpperCase(), 33, 67);
|
|
g2.drawString(nameWritten.toUpperCase(), 33, 67);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|