package com.docus.server;

import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class ImageProcessingExample {

    public static void main(String[] args) throws Exception {

//        UploadBatchFileRequest uploadBatchFileParam = new UploadBatchFileRequest();
//        System.out.println(JSON.toJSON(uploadBatchFileParam));
//
//        FileDTO fileDto = new FileDTO();
//        System.out.println(JSON.toJSON(fileDto));
//
//        List<FileDTO> fileDtoList = new ArrayList<>();
//        System.out.println(JSON.toJSON(fileDtoList));


        // 1. 调整图片大小
        ImgUtil.scale(FileUtil.file("C:\\Users\\dataexa\\Desktop\\麻醉.jpg"), FileUtil.file("C:\\Users\\dataexa\\Desktop\\output-麻醉.jpg"), 0.5f);

        // 2. 裁剪图片
//        ImgUtil.cut(FileUtil.file("C:\\Users\\dataexa\\Desktop\\麻醉.jpg"), FileUtil.file("C:\\Users\\dataexa\\Desktop\\output1.jpg"), new Rectangle(50, 50, 2400, (3527 / 2) / 2)); // 从input.jpg中裁剪出一个200x200的区域，保存为output.jpg

        // 5. 图片旋转
//        Image image = ImgUtil.rotate(ImageIO.read(FileUtil.file("C:\\Users\\dataexa\\Desktop\\麻醉.jpg")), 90);
//        ImgUtil.write(image, FileUtil.file("C:\\Users\\dataexa\\Desktop\\output2.jpg"));

//        uploadByte("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174051\\麻醉.jpg");
    }

    public static void uploadByte(String path) {
        File toFile = new File(path);
        Map data = new HashMap();
        data.put("file", toFile);
        data.put("filetype", "jpg");
        String body = HttpRequest.post("http://192.168.16.85:9999/uploadfile")
            .form(data)
            .contentType("multipart/form-data")
            .execute()
            .body();
        if (StrUtil.isNotBlank(body)) {
//            OcrResponse jsonRootBean = JSON.parseObject(body, OcrResponse.class);
//            System.out.println(jsonRootBean);
        }

//        Boolean success = (Boolean)result.get("success");
//        BigDecimal time = (BigDecimal)result.get("time");

    }


}
