use nginx variable to get magick (#20)

* use nginx variable to get magick

* remove comments
This commit is contained in:
木逸辰
2021-09-12 11:01:41 +08:00
committed by GitHub
parent fa8dea9e03
commit a0fdd62319
3 changed files with 25 additions and 16 deletions
+7 -8
View File
@@ -13,14 +13,13 @@ 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
-- linux -- 从 nginx 变量取
local magick = "/usr/local/ImageMagick/bin/magick" local magick = ngx.var.magick
local tmp = io.open(magick,"r")
if tmp == nil then if not magick then
-- mac os ngx.status = 500
magick = "/usr/local/bin/magick" ngx.say("image magick not found.")
else return
io.close(tmp)
end end
local result, _, code = os.execute(magick .. " convert -append " .. table.concat(origin, " ") .. " " .. combined) local result, _, code = os.execute(magick .. " convert -append " .. table.concat(origin, " ") .. " " .. combined)
+1
View File
@@ -51,6 +51,7 @@ while true do
table.insert(files, file_name) table.insert(files, file_name)
end end
-- 这里要重置一下file_name,否则后面的文件保存时会导致前面已保存的文件变成空文件 -- 这里要重置一下file_name,否则后面的文件保存时会导致前面已保存的文件变成空文件
-- file:flush() 和 io.flush() 都没效果
file_name = nil file_name = nil
file = nil file = nil
elseif typ == "eof" then elseif typ == "eof" then
+17 -8
View File
@@ -1,12 +1,21 @@
local magick = "/usr/local/ImageMagick/bin/magick" -- read from nginx var config
local tmp = io.open(magick,"r") local magick = ngx.var.magick
if tmp == nil then ngx.log(ngx.ERR, 'var', magick)
-- in mac os -- or use which command to get
magick = "/usr/local/bin/magick" if not magick then
else local exec = io.popen("which magick")
io.close(tmp) local tmp = exec:read("*a")
magick = string.gsub(tmp, "%s+", "")
exec:close()
end end
print(magick) if not magick then
ngx.status = 500
ngx.say("image magick not found.")
return
end
ngx.say(magick)
--local origin = { --local origin = {
-- "/Users/moicen/Music/alchemy/Song-of-joy.png", -- "/Users/moicen/Music/alchemy/Song-of-joy.png",