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
|
|
|
|
|
-- in linux
|
|
|
|
|
local magick = "/usr/local/ImageMagick/bin/magick"
|
|
|
|
|
local tmp = io.open(magick,"r")
|
|
|
|
|
if tmp == nil then
|
|
|
|
|
-- in 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)
|