Skip to content

Instantly share code, notes, and snippets.

@maugre
Forked from perusio/gist:2133228
Last active August 29, 2015 14:10
Show Gist options
  • Save maugre/4d0da857ceaac48d4e0c to your computer and use it in GitHub Desktop.
Save maugre/4d0da857ceaac48d4e0c to your computer and use it in GitHub Desktop.
## Get the size of the image file using Lua.
## Cf. http://wiki.nginx.org/HttpLuaModule#set_by_lua.
location ~* \.(?:gif|jpe?g|png)$ {
set_by_lua $img_file_size '
function fsize (file)
local current = file:seek() -- get current position
local size = file:seek("end") -- get file size
file:seek("set", current) -- restore position
return size
end
fsize(ngx.var.request_filename)';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment