Quellcode durchsuchen

Merge remote-tracking branch 'origin/master'

syh vor 5 Jahren
Ursprung
Commit
2afc03a7fb

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/utils/HttpUtils.java

@@ -141,6 +141,8 @@ public class HttpUtils {
             }
             List<NameValuePair> paramList = new ArrayList<NameValuePair>();
             for (String key : param.keySet()) {
+                System.out.println(key + "=" + String.valueOf(param.get(key)));
+                System.out.println("-------------------------------------");
                 BasicNameValuePair basicNameValuePair = new BasicNameValuePair(key, String.valueOf(param.get(key)));
                 paramList.add(basicNameValuePair);
             }

+ 115 - 142
module-common/src/main/java/cn/com/ctop/common/utils/ImageUtils.java

@@ -94,187 +94,160 @@ public class ImageUtils {
 
     }
 
-    public void addTextInImage(InputStream input, String content, Color color, Font font) throws IOException {
+    public void addTextInImage(String theme, InputStream input, String content, Color color, Font font, String borderPath, String coverPath, int borderOffsiteX, int borderOffsiteY, int contentOffsiteX, int contentOffsiteY) throws IOException {
         Image image = ImageIO.read(input);
         int width = image.getWidth(null);
         int height = image.getHeight(null);
         BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
-        Graphics2D graphics = bufferedImage.createGraphics();
-        graphics.drawImage(image, 0, 0, width, height, null);
-        graphics.setColor(color);
-        graphics.setFont(font);
+        Graphics2D graphics2D = bufferedImage.createGraphics();
+        graphics2D.drawImage(image, 0, 0, width, height, null);
+        graphics2D.setColor(color);
+        graphics2D.setFont(font);
+        File borderFile = new File(borderPath);
 
-        Image borderImage = ImageIO.read(new File("D:/border/images/white01.png"));
+        Image borderImage = ImageIO.read(borderFile);
 //        BufferedImage bufferedImage2 = new BufferedImage(borderImage.getWidth(null),borderImage.getHeight(null),BufferedImage.TYPE_INT_RGB);
-        graphics.drawImage(borderImage, 50, height / 2 + 100, null);
+        graphics2D.drawImage(borderImage, borderOffsiteX, height / 2 + borderOffsiteY, null);
 
 //        graphics2D.setColor(Color.BLUE.darker().darker());
 //        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-        graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
-        graphics.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
+        graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
 //        graphics2D.setStroke(new BasicStroke(5.0f ,
 //                BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 15.0f, new float[] {10.0f,10.0f}, 5.0f));
-        FontRenderContext frc = graphics.getFontRenderContext();
-        int x = 150;
-        int y = height / 2 + 220;
-        if (content.length() < 9) {
-//            TextLayout tl = new TextLayout(content, font, frc);
-//            Shape sha = tl.getOutline(AffineTransform.getTranslateInstance(5,25));
-//            graphics2D.setStroke(new BasicStroke(3.0f));
-//            graphics2D.setColor(Color.black);
-//            graphics2D.draw(sha);
-//            graphics2D.setColor(Color.white);
-//            graphics2D.fill(sha);
-//            graphics2D.dispose();
-            graphics.drawString(content, x, y);
-        } else {
-            graphics.drawString(content.substring(0, 8), x, y);
-            graphics.drawString(content.substring(8), x, y + 60);
-//            TextLayout tl = new TextLayout(content.substring(0,8), font, frc);
-//            Shape sha = tl.getOutline(AffineTransform.getTranslateInstance(5,25));
-//            graphics2D.setStroke(new BasicStroke(3.0f));
-//            graphics2D.setColor(Color.WHITE);
-//            graphics2D.draw(sha);
-//            graphics2D.setColor(Color.BLACK);
-//            graphics2D.fill(sha);
-////            graphics2D.dispose();
-//
-//            TextLayout t2 = new TextLayout(content.substring(8), font, frc);
-//            Shape sha2 = t2.getOutline(AffineTransform.getTranslateInstance(5,25));
-//            graphics2D.setStroke(new BasicStroke(3.0f));
-//            graphics2D.setColor(Color.WHITE);
-//            graphics2D.draw(sha2);
-//            graphics2D.setColor(Color.BLACK);
-//            graphics2D.fill(sha);
-////            graphics2D.dispose();
-        }
-
-        graphics.dispose();
-        FileOutputStream fileOutputStream = new FileOutputStream("D:/image/cover/" + UUID.randomUUID() + ".jpg");
+        FontRenderContext frc = graphics2D.getFontRenderContext();
+        int x = contentOffsiteX;
+        int y = height / 2 + contentOffsiteY;
+//        if (content.length() < 9) {
+//            graphics2D.drawString(content, x, y);
+//        } else {
+//            graphics2D.drawString(content.substring(0, 8), x, y);
+//            graphics2D.drawString(content.substring(8), x, y + 60);
+//        }
+        AffineTransform affineTransform = new AffineTransform();
+        affineTransform.rotate(Math.toRadians(-5), 360, 800);
+//        Font rotatedFont = font.deriveFont(affineTransform);
+//        graphics2D.setFont(font);
+        graphics2D.setTransform(affineTransform);
+        graphics2D.drawString(content, x, y);
+
+//        graphics2D.setTransform(trans);
+        graphics2D.dispose();
+        FileOutputStream fileOutputStream = new FileOutputStream(coverPath + "/" + theme + "_" + font.getFontName() + "_" + borderFile.getName() + "_" + content + UUID.randomUUID() + ".jpg");
         ImageIO.write(bufferedImage, "jpg", fileOutputStream);
 
     }
 
-    public int getContentLength(String content, Graphics2D graphics) {
-        return graphics.getFontMetrics(graphics.getFont()).charsWidth(content.toCharArray(), 0, content.length());
+    public int getContentLength(String content, Graphics2D graphics2D) {
+        return graphics2D.getFontMetrics(graphics2D.getFont()).charsWidth(content.toCharArray(), 0, content.length());
     }
 
     public static void main(String[] args) {
         ImageUtils i = new ImageUtils();
-        Font font = new Font("微软雅黑", Font.BOLD + Font.PLAIN, 35);
-
-//        String content = "测试封面文字内容\n最多可以十五字";
-        Color color = new Color(0, 0, 0, 255);
+        String theme = "两件套";
+        Font font = new Font("Aa棉花糖", Font.BOLD + Font.PLAIN, 60);
+        String borderPath = "D:/border/mb/ff0099.png";
+        String coverPath = "D:/image/cover/" + theme;
+        String sourcePath = "D:/image/source/" + theme;
+        String targetPath = "D:/image/target/" + theme;
+        File coverFile = new File(coverPath);
+        if (!coverFile.exists()) {
+            coverFile.mkdirs();
+        }
+//        int bx = 20;
+//        int by = 50;
+//        int cx = 80;
+//        int cy = 220;
+
+//        int bx = 20;
+//        int by = 50;
+//        int cx = 105;
+//        int cy = 170;
+
+        int bx = 20;
+        int by = 50;
+        int cx = 70;
+        int cy = 200;
+
+        Color color = new Color(255, 0, 153, 255);
         List<String> list = i.getContentList();
-//        File file = new File("D:/bg1.jpg");
-        File file = new File("D:/image/target");
+        File sourceFile = new File(sourcePath);
+
+        String[] sourceFiles = sourceFile.list();
+        for (String str : sourceFiles) {
+            String imagePath = sourceFile.getAbsolutePath() + "/" + str;
+            System.out.println(imagePath);
+            new ImageUtils().resize(720, 1280, imagePath, targetPath + "/" + UUID.randomUUID() + ".jpg");
+        }
+
+        File file = new File(targetPath);
+        if (!file.exists()) {
+            file.mkdirs();
+        }
         String[] files = file.list();
         for (String str : files) {
             String imagePath = file.getAbsolutePath() + "/" + str;
             try {
+                System.out.println(imagePath);
                 File imageFile = new File(imagePath);
                 for (String content : list) {
                     InputStream inputStream = new FileInputStream(imageFile);
-                    i.addTextInImage(inputStream, content, color, font);
+                    i.addTextInImage(theme, inputStream, content, color, font, borderPath, coverPath, bx, by, cx, cy);
                 }
             } catch (IOException e) {
                 e.printStackTrace();
             }
-//            new ImageUtils().resize(720,1280,imageFile,"D:/image/target/"+ UUID.randomUUID()+".jpg");
+//
         }
 
 
-        System.out.println();
+        System.out.println("ok");
 //
     }
 
     public List<String> getContentList() {
         List<String> list = new ArrayList<String>();
-        list.add("想尝试一下这种风格");
-        list.add("想看一下效果");
-        list.add("这是个狠人");
-        list.add("难得一见");
-        list.add("每一个都很饱满");
-        list.add("土豪吃法");
-        list.add("怕了怕了");
-        list.add("我反正不敢");
-        list.add("贪吃的后果");
-        list.add("求打败,在线等");
-        list.add("女人心海底针");
-        list.add("撕开赚钱的真相");
-        list.add("这是啥味儿");
-        list.add("爪子的妙用");
-        list.add("把聊天记录删除后..");
-        list.add("章鱼,太狠了");
-        list.add("先下手为强");
-        list.add("爪子的妙用");
-        list.add("听说这是村里的帅哥");
-        list.add("听说这是村里的美女");
-        list.add("没想到,饭还能这样吃");
-        list.add("没想到,水还能这样喝");
-        list.add("没想到,衣服还能这样穿");
-        list.add("没想到,车还能这样骑");
-        list.add("没想到,妆还能这样画");
-        list.add("她扒拉我");
-        list.add("三者必有一伤");
-        list.add("最新机械皮肤");
-        list.add("妹子,这吃的啥");
-        list.add("活下来,算我输");
-        list.add("不哭算我输");
-        list.add("不摔算我输");
-        list.add("送礼物吓傻女友");
-        list.add("是谁在唱歌");
-        list.add("表情包不够,大长腿来凑");
-        list.add("这场面真没见过");
-        list.add("这蔬菜得回家供着");
-        list.add("挖掘机哪家强");
-        list.add("高手过招");
-        list.add("还没怕过谁");
-        list.add("手有点干巴");
-        list.add("准备装箱");
-        list.add("手把手教学");
-        list.add("别怪我不客气");
-        list.add("放大招了!");
-        list.add("难怪我这么穷");
-        list.add("招招毙命");
-        list.add("随时准备辞职");
-        list.add("不秀的李白");
-        list.add("没大的黄忠");
-        list.add("总是碰见猴子的鲁班");
-        list.add("这样哄女友很管用");
-        list.add("三年的聊天记录");
-        list.add("用它不怕女神追不到");
-        list.add("就靠你了");
-        list.add("比谁快!");
-        list.add("城里人真会玩");
-        list.add("斗图我还没输过谁");
-        list.add("开局斗图,把它斗哭了");
-        list.add("敢和我来斗图");
-        list.add("一起斗图啊");
-        list.add("斗图你怕了吗");
-        list.add("斗图输了的结果");
-        list.add("斗图王者重出江湖");
-        list.add("斗图还是我最强");
-        list.add("打字就是表情包");
-        list.add("现在表白都靠斗图了");
-        list.add("斗图啊,王者在线等");
-        list.add("斗图吗,年轻人");
-        list.add("斗图能赚零花钱");
-        list.add("确认过眼神,是我斗不过的人");
-        list.add("年轻人爱的斗图软件");
-        list.add("教你一招,包情包用不完");
-        list.add("从此人生很有趣");
-        list.add("我不认输,我只斗图");
-        list.add("表情包不够用?");
-        list.add("斗图,你过来呀!");
-        list.add("斗图输了不开心");
-        list.add("斗图输了不要怕");
-        list.add("还怕表情包不够用?");
-        list.add("表情包太少的后果");
-        list.add("斗图秒赢!");
-        list.add("是谁还在盗图?");
+        //秋装
+//        list.add("不露腿也能穿得心机");
+//        list.add("原来还能这么穿");
+//        list.add("女生本来就该这样穿");
+//        list.add("逆袭打脸渣男");
+//        list.add("你适合穿裙子还是裤子");
+//        list.add("同样的衣服,她却");
+//        list.add("出门逛街的首选");
+//        list.add("约会必备的穿搭");
+//        list.add("这样穿直男瞬间KO");
+//        list.add("女生还是这样穿漂亮");
+
+        //显瘦
+//        list.add("胖妹子救星一招显瘦");
+//        list.add("微胖也能穿出女神范儿");
+//        list.add("我不减肥都比你好看");
+//        list.add("她再也不敢炫耀了");
+//        list.add("显瘦本来就该这样穿");
+//        list.add("变装后的差别待遇");
+//        list.add("女孩变装后漂亮大方");
+//        list.add("男人都喜欢这样的");
+//        list.add("男友喜欢女生的样子");
+//        list.add("发了工资一定要");
+
+        //两件套
+        list.add("这样的两件套真的值了");
+        list.add("论两件套的正确穿搭");
+        list.add("怎样穿更少女");
+        list.add("减龄10岁的正确穿搭");
+        list.add("这样穿就对了");
+        list.add("女神衣柜必备套装");
+        list.add("改变自己学习穿搭");
+        list.add("这样穿不怕撞衫");
+        list.add("见男友这样穿让他后悔");
+        list.add("这样穿不简单");
+
+
+
         return list;
     }
 }
+

Datei-Diff unterdrückt, da er zu groß ist
+ 6 - 4
module-crawler/src/main/java/cn/com/ctop/crawler/modules/core/service/impl/KuaishouCrawlerServiceImpl.java