lua-resty-qrencode is a wrapper of libqrencode with libpng for OpenResty(nginx_lua).
lua-resty-qrencode is dependent on libqrencode and libpng, so make sure these are installed before compile it.
$ brew install libqrencode
$ git clone https://github.com/orangle/lua-resty-qrencode.git
$ cd lua-resty-qrencode
$ make
$ make install
defalut openresty PREFIX
is /usr/local/openresty
, if you have a different path, please read Makefile
and change the path.
please install libqrencode and libpng, and read Makefile. or you can see http://blog.csdn.net/orangleliu/article/details/64912578#t0
location /qrcode {
content_by_lua_block {
local qr = require("qrencode")
local args = ngx.req.get_uri_args()
local text = args.text
if text == nil or text== "" then
ngx.say('need a text param')
ngx.exit(404)
end
ngx.say(qr {
text=text,
level="L",
kanji=false,
ansi=true,
size=4,
margin=2,
symversion=0,
dpi=78,
casesensitive=true,
foreground="48AF6D",
background="3FAF6F"
})
}
}
test url like
curl 'http://127.0.0.1:8008/qrcode?text=http://orangleliu.info'
when pass a table, "text" is required and other is optional.
location /qrcode {
content_by_lua_block {
local qr = require("qrencode")
local args = ngx.req.get_uri_args()
local text = args.text
if text == nil or text== "" then
ngx.say('need a text param')
ngx.exit(404)
end
ngx.say(qr {
text=text,
level="L",
kanji=false,
ansi=false,
size=4,
margin=2,
symversion=0,
dpi=78,
casesensitive=true,
foreground="000000",
background="FFFFFF"
})
}
default_type image/png;
add_header Expires "Fri, 01 Jan 1980 00:00:00 GMT";
add_header Pragma "no-cache";
add_header Cache-Control "no-cache, max-age=0, must-revalidate";
}
type url like 'http://127.0.0.1:8008/qrcode?text=http://orangleliu.info' in browser, you can get a png image.