add combine image logic (#14)

* add combine image logic

* remove unnecessary log
This commit is contained in:
木逸辰
2021-09-06 18:56:59 +08:00
committed by GitHub
parent d1253478a7
commit c7a35c4744
5 changed files with 72 additions and 16 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ server {
server_name music-room.alchemy-studio.cn;
listen 443 ssl;
set $tmp_file_dir "/file_upload/"; # 文件存储路径
set $tmp_file_dir "/file_upload"; # 文件存储路径
set $task_server "http://127.0.0.1:8080"; # task server host
location / {
+32 -5
View File
@@ -1,5 +1,32 @@
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by moicen.
--- DateTime: 2021/9/4 12:28
---
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)
+14 -4
View File
@@ -21,8 +21,15 @@ while true do
end
if typ == "header" then
file_name = string.format("%s/%s.jpeg", file_dir, uuid())
ngx.log(ngx.ERR, "file name", file_name)
--"Content-Disposition","form-data; name=\"files[]\"; filename=\"Song-of-joy.png\""
--"Content-Disposition","form-data; name=\"files[]\"; filename=\"rhythm-recognition-1.png\""
local key, val = res
if (key == "Content-Disposition") then
local ext = ngx.re.match(val, [[filename=".*\.(\w+)"]], "jo")
file_name = string.format("%s/%s.%s", file_dir, uuid(), ext)
end
if file_name then
file = io.open(file_name, "w+")
if not file then
@@ -45,13 +52,16 @@ while true do
elseif typ == "eof" then
local http = require "resty.http"
local httpc = http.new()
local remote_url = string.format("%s/api/v1/ts/task_server/create_task", task_server)
local remote_url = string.format("%s/api/v1/ts/create_task", task_server)
local res, err = httpc:request_uri(
remote_url,
{
method = "POST",
headers = {
host = "ngx"
},
body = {
cjson.encode({task_type = 1, data = files, created_by = 'openresty'})
cjson.encode({task_type = 1, data = files, created_by = 'ngx', updated_by = 'ngx'})
},
}
)
+25
View File
@@ -0,0 +1,25 @@
--local str = "form-data; name=\"files[]\"; filename=\"Song-of-joy.png\""
--local ext = ngx.re.match(str, [[filename=".*\.(\w+)"]], "jo")
--print(ext)
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
print(magick)
--
--local origin = {
-- "/Users/moicen/Music/alchemy/Song-of-joy.png",
-- "/Users/moicen/Music/alchemy/You-and-me.png"
--}
--origin = table.concat(origin, " ")
--ngx.log(ngx.ERR, origin)
--local file = io.popen("/usr/local/bin/magick convert -append " .. origin .. " /tmp/combined.jpeg" )
--local output = file:read("*all")
--file:close()
--ngx.say(output)
-6
View File
@@ -1,8 +1,2 @@
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by moicen.
--- DateTime: 2021/9/4 12:20
---
ngx.say('file dir...', ngx.var.tmp_file_dir)
ngx.say('task server...', ngx.var.task_server)