Handle error with combine (#16)
* check if failed when combine image * add status code when combine failed
This commit is contained in:
+14
-10
@@ -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 content = file:read("*all")
|
||||
file:close()
|
||||
os.remove(combined)
|
||||
ngx.say(content)
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user