add image check when combine (#26)

This commit is contained in:
木逸辰
2021-09-24 20:18:39 +08:00
committed by GitHub
parent af6dfada30
commit c966f77142
4 changed files with 14 additions and 137 deletions
+12 -4
View File
@@ -5,12 +5,18 @@ 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"]
ngx.log(ngx.INFO, 'REQ_BODY -> ', ngx.req.get_body_data())
local data = req_body["data"]["images"]
local combined = file_dir .. "/" .. uuid.generate_v4() .. ".jpeg";
local len = table.getn(data)
if len == 0 then
ngx.status = 500
ngx.say("No images to combine!")
return;
end
local origin = {}
for i = 1, len do
ngx.log(ngx.INFO, "COMBINE FILE ->", data[i])
origin[i] = file_dir .. "/" .. data[i] .. " "
end
-- 从 nginx 变量取
@@ -26,7 +32,9 @@ if not magick then
magick = ""
end
local result, _, code = os.execute(magick .. " convert -append " .. table.concat(origin, " ") .. " " .. combined)
local cmd = magick .. " convert -append " .. table.concat(origin, " ") .. " " .. combined
ngx.log(ngx.INFO, 'CMD -> ', cmd)
local result, _, code = os.execute(cmd)
if result and code == 0 then
local file = io.open(combined)
local content = file:read("*all")
@@ -36,4 +44,4 @@ if result and code == 0 then
else
ngx.status = 500
ngx.say("image combine failed.")
end
end