URL转图片、pdf及图片分割

URL转图片、pdf及图片分割

URL转图片

//        BrowserFetcher.downloadIfNotExist(null);
        ArrayList<String> arrayList = new ArrayList<>();
//生成pdf必须在无厘头模式下才能生效
        arrayList.add("--no-sandbox");
        arrayList.add("--disable-setuid-sandbox");
        LaunchOptions options = new LaunchOptionsBuilder().withArgs(arrayList).withHeadless(true).build();
        Browser browser = null;
        try {
            browser = Puppeteer.launch(options);
            Page page = browser.newPage();
            page.goTo("https://blog.csdn.net/qq285679784/article/details/118892783");
            PDFOptions pdfOptions = new PDFOptions();
            pdfOptions.setPath("test.pdf");
            pdfOptions.setPrintBackground(true);
            page.pdf(pdfOptions);
//            ScreenshotOptions screenshotOptions = new ScreenshotOptions();
//            screenshotOptions.setFullPage(true);
            screenshotOptions.setOmitBackground(true);
//            screenshotOptions.setPath("test.png");
//            screenshotOptions.setType("png");
//            page.screenshot(screenshotOptions);
            page.close();
        } catch (Exception e) {
            System.out.println(e);
        } finally {
            if (browser != null) {
                browser.close();
            }
        }

图片分割成16:9

String originalImg = "test.png";
        // 读入大图
        File file = new File(originalImg);
        FileInputStream fis = new FileInputStream(file);
        System.out.println(file.exists());
        BufferedImage image = ImageIO.read(fis);


        // 计算每个小图的宽度和高度
        int imgWidth = image.getWidth();
        int imgHeight = image.getHeight();
//        int chunkWidth = imgWidth / cols;
        int chunkHeight = imgWidth*9/16;
        int chunks = (int)Math.ceil((double)(16*imgHeight)/(imgWidth*9));
        System.out.println("图片的宽度为:" + imgWidth + "图片的高度为:" + imgHeight);//230,278
        BufferedImage imgs[] = new BufferedImage[chunks];
        int count = 0;
        for (int i = 0; i < chunks; i++) {
            if (i < chunks-1) {
                imgs[count] = new BufferedImage(imgWidth, chunkHeight, image.getType());
                Graphics2D gr = imgs[count++].createGraphics();
                gr.drawImage(image, 0, 0, imgWidth, chunkHeight, 0, chunkHeight * i, imgWidth, chunkHeight * (i+1), null);
//            System.out.println("源矩阵第一个角的坐标" + chunkWidth * y + "+" + chunkHeight * x + "源矩阵第二个角的坐标" + chunkWidth * (y + 1) + "+" + chunkHeight * (x + 1));
                gr.dispose();
            } else {
                imgs[count] = new BufferedImage(imgWidth, imgHeight-chunkHeight*i, image.getType());
                Graphics2D gr = imgs[count++].createGraphics();
                gr.drawImage(image, 0, 0, imgWidth, imgHeight-chunkHeight*i, 0, chunkHeight * i, imgWidth, imgHeight, null);
            }
        }

        //大图中的一部分
//        int count = 0;
//        BufferedImage imgs[] = new BufferedImage[chunks];
//        for (int x = 0; x < rows; x++) {
//            for (int y = 0; y < cols; y++) {
//                //设置小图的大小和类型
//                imgs[count] = new BufferedImage(chunkWidth, chunkHeight, image.getType());
//
//                //写入图像内容
//                Graphics2D gr = imgs[count++].createGraphics();
//                gr.drawImage(image, 0, 0, chunkWidth, chunkHeight, chunkWidth * y, chunkHeight * x, chunkWidth * y + chunkWidth, chunkHeight * x + chunkHeight, null);
//                System.out.println("源矩阵第一个角的坐标" + chunkWidth * y + "+" + chunkHeight * x + "源矩阵第二个角的坐标" + chunkWidth * (y + 1) + "+" + chunkHeight * (x + 1));
//                gr.dispose();
//                /*
//                 源矩阵第一个角的坐标0+0源矩阵第二个角的坐标77+92
//                 源矩阵第一个角的坐标77+0源矩阵第二个角的坐标154+92
//                 源矩阵第一个角的坐标154+0源矩阵第二个角的坐标231+92
//                 源矩阵第一个角的坐标0+92源矩阵第二个角的坐标77+184
//                 源矩阵第一个角的坐标77+92源矩阵第二个角的坐标154+184
//                 源矩阵第一个角的坐标154+92源矩阵第二个角的坐标231+184
//                 源矩阵第一个角的坐标0+184源矩阵第二个角的坐标77+276
//                 源矩阵第一个角的坐标77+184源矩阵第二个角的坐标154+276
//                 源矩阵第一个角的坐标154+184源矩阵第二个角的坐标231+276
//                */
//            }
//        }
        // 输出小图
        for (int i = 0; i < imgs.length; i++) {
            //ImageIO.write(imgs[i], "jpg", new File("C:\\img\\split\\img" + i + ".jpg"));
            ImageIO.write(imgs[i], "png", new File("test" + i + ".png"));
            System.out.println(i);
        }

        System.out.println("完成分割!");

我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客:

  1. 全新的界面设计 ,将会带来全新的写作体验;
  2. 在创作中心设置你喜爱的代码高亮样式,Markdown 将代码片显示选择的高亮样式 进行展示;
  3. 增加了 图片拖拽 功能,你可以将本地的图片直接拖拽到编辑区域直接展示;
  4. 全新的 KaTeX数学公式 语法;
  5. 增加了支持甘特图的mermaid语法1 功能;
  6. 增加了 多屏幕编辑 Markdown文章功能;
  7. 增加了 焦点写作模式、预览模式、简洁写作模式、左右区域同步滚轮设置 等功能,功能按钮位于编辑区域与预览区域中间;
  8. 增加了 检查列表 功能。

  1. mermaid语法说明 ↩︎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值