Handle error with combine (#16)

* check if failed when combine image

* add status code when combine failed
This commit is contained in:
木逸辰
2021-09-07 21:54:52 +08:00
committed by GitHub
parent 49e4710203
commit 3d2e03be82
+10 -6
View File
@@ -13,20 +13,24 @@ local origin = {}
for i = 1, len do
origin[i] = file_dir .. "/" .. data[i] .. " "
end
-- in linux
-- linux
local magick = "/usr/local/ImageMagick/bin/magick"
local tmp = io.open(magick,"r")
if tmp == nil then
-- in mac os
-- mac os
magick = "/usr/local/bin/magick"
else
io.close(tmp)
end
local file = io.popen(magick .. " convert -append " .. table.concat(origin, " ") .. " " .. combined)
file:read("*all")
file:close()
file = io.open(combined)
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