package com.fs.app.controller;




import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class imgToken {
    private static final int TOKEN_DIVISOR = 784;
    private static final int TOKEN_LIMIT = 1312;

    public static void main(String[] args) {
        // 替换为你自己的图片 URL
        String imageUrl = "https://cos.his.cdwjyyh.com/fs/20250526/a17565cb7ba74aefb27e27ac91f802f2.jpg";

        try {
            BufferedImage image = ImageIO.read(new URL(imageUrl));
            if (image == null) {
                System.out.println("无法加载图片，请检查 URL 是否正确");
                return;
            }

            int width = image.getWidth();
            int height = image.getHeight();

            int tokenEstimate = (int) Math.ceil((width * height) / (double) TOKEN_DIVISOR);

            System.out.println("图片尺寸: " + width + " x " + height);
            System.out.println("估算消耗 Token: " + tokenEstimate);
            System.out.println("Token 上限: " + TOKEN_LIMIT);
            if (tokenEstimate > TOKEN_LIMIT) {
                System.out.println("⚠️ 超出 token 上限！");
            } else {
                System.out.println("✅ 在 token 限制范围内");
            }

        } catch (IOException e) {
            System.out.println("图片加载失败：" + e.getMessage());
        }
    }
}
