添加bimg

This commit is contained in:
HKXluo
2025-05-04 20:13:17 +08:00
parent a1e8ca9a15
commit f09c7d77a8
7 changed files with 1156 additions and 5 deletions

View File

@@ -0,0 +1,67 @@
-- API 地址 / API Endpoint
local API_URL = "http://newgmapi.liulikeji.cn/api/sanjuuni"
-- 输入图片URL / Input image URL
local INPUT_URL = "https://git.liulikeji.cn/xingluo/CCTweaked-Demo/raw/branch/main/Demo/SanjuuniApi-Demo/demo.gif"
local function Get_image_url(INPUT_URL,API_URL,args,output_format)
-- ===== 1. 发送HTTP请求 / Send HTTP request =====
local requestData = {
input_url = INPUT_URL,
args = args,
output_format = output_format
}
local response, err = http.post(
API_URL,
textutils.serializeJSON(requestData),
{ ["Content-Type"] = "application/json" }
)
-- ===== 2. 读取数据 / Send HTTP request =====
if not response then error("HTTP Request Failure: "..(err or "Unknown error"))
else
-- 读取响应 / Read response
local responseData = textutils.unserializeJSON(response.readAll())
response.close()
--返回下载链接 / Return download URL
if responseData.status ~= "success" then error("Conversion failed:"..(responseData.error or "Unknown error"))
else
return responseData.download_url
end
end
end
-- 图片宽度 / Image width
local width, height = term.getSize() -- 获取终端尺寸width=宽度height=高度)
local width = width * 2 -- 宽度×2
local height = height * 3 -- 高度×3
-- 转换参数 / Conversion parameters
args = { "-8","--width="..width,"--height="..height }
output_format = "bimg"
-- 调用API / Call API
local download_url = Get_image_url(INPUT_URL,API_URL,args,output_format)
-- 下载图像文件 / Download image file
print("\nConversion successful! Download URL:")
print(download_url)
luafile = http.get(download_url)
if luafile then
print("\nLua file downloaded successfully.")
-- 保存Lua文件 / Save Lua file
f = fs.open("demo.bimg", "w")
f.write(luafile.readAll())
f.close()
print("\nLua file saved as demo.bimg.")
else
print("\nFailed to download Lua file.")
end