wangqifan hace 3 años
padre
commit
15352556fc

+ 28 - 8
src/main/java/com/izouma/nineth/service/DomainOrderService.java

@@ -220,9 +220,9 @@ public class DomainOrderService {
         String domainName;
         if (domain.contains(".")) {
             int dotIndex = domain.indexOf(".");
-            domainName = domain.substring(0, dotIndex);
+            domainName = domain.substring(0, dotIndex).toUpperCase();
         } else {
-            domainName = domain;
+            domainName = domain.toUpperCase();
         }
         InputStream is1 = this.getClass()
                 .getResourceAsStream("/font/Akronim Regular_mianfeiziti1.ttf");
@@ -264,13 +264,33 @@ public class DomainOrderService {
 
 
         int domainLength = domainName.length();
-        if (domainLength > 4 & domainLength < 11) {
+        if (domainLength > 10) {
             g.setColor(new Color(255, 255, 255));
-            Font topFont = font1.deriveFont(Font.PLAIN, 200f);
+            Font topFont = font1.deriveFont(Font.PLAIN, 130f);
+            Font downFont = font2.deriveFont(Font.BOLD, 36f);
+            int subIndex = domainLength / 3;
+            String str1 = domainName.substring(0, subIndex);
+            String str2 = domainName.substring(subIndex, subIndex + subIndex);
+            String str3 = domainName.substring(subIndex + subIndex, domainLength);
+            ImageUtils.drawCenteredString(g, str1, new Rectangle(0, 180, shareImg
+                    .getWidth(), 86), topFont);
+            ImageUtils.drawCenteredString(g, str2, new Rectangle(0, 300, shareImg
+                    .getWidth(), 86), topFont);
+            ImageUtils.drawCenteredString(g, str3, new Rectangle(0, 420, shareImg
+                    .getWidth(), 86), topFont);
+            ImageUtils.drawCenteredString(g, ".NFT", new Rectangle(0, 540, shareImg
+                    .getWidth(), 86), topFont);
+            g.setColor(new Color(255, 255, 255));
+            ImageUtils.drawCenteredString(g, domain, new Rectangle(0, 650, shareImg
+                    .getWidth(), 12), downFont);
+        }
+        if (domainLength > 5 & domainLength <= 10) {
+            g.setColor(new Color(255, 255, 255));
+            Font topFont = font1.deriveFont(Font.PLAIN, 190f);
             Font downFont = font2.deriveFont(Font.BOLD, 36f);
             int subIndex = domainLength / 2;
-            String str1 = domainName.substring(0, subIndex + 1);
-            String str2 = domainName.substring(subIndex + 1, domainLength);
+            String str1 = domainName.substring(0, subIndex);
+            String str2 = domainName.substring(subIndex, domainLength);
             ImageUtils.drawCenteredString(g, str1, new Rectangle(0, 180, shareImg
                     .getWidth(), 86), topFont);
             ImageUtils.drawCenteredString(g, str2, new Rectangle(0, 350, shareImg
@@ -281,9 +301,9 @@ public class DomainOrderService {
             ImageUtils.drawCenteredString(g, domain, new Rectangle(0, 650, shareImg
                     .getWidth(), 12), downFont);
         }
-        if (domainLength < 5) {
+        if (domainLength <= 5) {
             g.setColor(new Color(255, 255, 255));
-            Font topFont = font1.deriveFont(Font.PLAIN, 240f);
+            Font topFont = font1.deriveFont(Font.PLAIN, 200f);
             Font downFont = font2.deriveFont(Font.BOLD, 36f);
             ImageUtils.drawCenteredString(g, domainName, new Rectangle(0, 243, shareImg
                     .getWidth(), 86), topFont);

+ 15 - 1
src/test/java/com/izouma/nineth/service/UserServiceTest.java

@@ -2,6 +2,7 @@ package com.izouma.nineth.service;
 
 import com.alibaba.fastjson.JSONObject;
 import com.alipay.api.AlipayApiException;
+import com.google.zxing.WriterException;
 import com.huifu.adapay.core.exception.BaseAdaPayException;
 import com.izouma.nineth.ApplicationTests;
 import com.izouma.nineth.config.Constants;
@@ -29,6 +30,9 @@ import org.apache.commons.lang3.StringUtils;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -40,6 +44,8 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
 
+import javax.imageio.ImageIO;
+
 @Slf4j
 @ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@@ -61,6 +67,8 @@ public class UserServiceTest extends ApplicationTests {
     private TeamService           teamService;
     @Autowired
     private NeteaseMessageService neteaseMessageService;
+    @Autowired
+    private DomainOrderService    domainOrderService;
 
     @Test
     public void findByUsernameAndDelFalse1() {
@@ -260,6 +268,12 @@ public class UserServiceTest extends ApplicationTests {
 
     @Test
     public void tTe() {
-        teamService.getUnreadCount("9850","7807550605");
+        teamService.getUnreadCount("9850", "7807550605");
+    }
+
+    @Test
+    public void shareImg() throws IOException, FontFormatException, WriterException {
+        BufferedImage img = domainOrderService.domainImg("thomeboydontkill.nft");
+        ImageIO.write(img, "jpg", new File("1.jpg"));
     }
 }