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 for i = 1, len do
origin[i] = file_dir .. "/" .. data[i] .. " " origin[i] = file_dir .. "/" .. data[i] .. " "
end end
-- in linux -- linux
local magick = "/usr/local/ImageMagick/bin/magick" local magick = "/usr/local/ImageMagick/bin/magick"
local tmp = io.open(magick,"r") local tmp = io.open(magick,"r")
if tmp == nil then if tmp == nil then
-- in mac os -- mac os
magick = "/usr/local/bin/magick" magick = "/usr/local/bin/magick"
else else
io.close(tmp) io.close(tmp)
end end
local file = io.popen(magick .. " convert -append " .. table.concat(origin, " ") .. " " .. combined)
file:read("*all") local result, _, code = os.execute(magick .. " convert -append " .. table.concat(origin, " ") .. " " .. combined)
file:close() if result and code == 0 then
file = io.open(combined) local file = io.open(combined)
local content = file:read("*all") local content = file:read("*all")
file:close() file:close()
os.remove(combined) os.remove(combined)
ngx.say(content) ngx.say(content)
else
ngx.status = 500
ngx.say("image combine failed.")
end