Files
resty_functions/prod/upload/combine.lua
T

35 lines
913 B
Lua
Raw Normal View History

2021-09-06 18:56:59 +08:00
local uuid = require "resty.jit-uuid"
local cjson = require "cjson"
uuid.seed()
local file_dir = ngx.var.tmp_file_dir
ngx.req.read_body()
local req_body = cjson.decode(ngx.req.get_body_data())
local data = req_body["data"]
local combined = file_dir .. "/" .. uuid.generate_v4() .. ".jpeg";
local len = table.getn(data)
local origin = {}
for i = 1, len do
origin[i] = file_dir .. "/" .. data[i] .. " "
end
2021-09-12 11:01:41 +08:00
-- 从 nginx 变量取
local magick = ngx.var.magick
if not magick then
ngx.status = 500
ngx.say("image magick not found.")
return
2021-09-06 18:56:59 +08:00
end
2021-09-07 21:54:52 +08:00
local result, _, code = os.execute(magick .. " convert -append " .. table.concat(origin, " ") .. " " .. combined)
if result and code == 0 then
local file = io.open(combined)
local content = file:read("*all")
file:close()
os.remove(combined)
ngx.say(content)
else
ngx.status = 500
ngx.say("image combine failed.")
end