Skip to content

Instantly share code, notes, and snippets.

@south37
Created March 28, 2014 13:07
Show Gist options
  • Save south37/b8f5ea138df4588ad3ac to your computer and use it in GitHub Desktop.
Save south37/b8f5ea138df4588ad3ac to your computer and use it in GitHub Desktop.
local path, ext =
ngx.var.path, ngx.var.ext
local images_dir = "/usr/local/var/www/manga/img/" -- where images come from
local cache_dir = "/usr/local/var/www/manga/cache/" -- where images are cached
local function return_not_found(msg)
ngx.status = ngx.HTTP_NOT_FOUND
ngx.header["Content-type"] = "text/html"
ngx.say(msg or "not found")
ngx.exit(0)
end
local source_fname = images_dir .. path
-- make sure the file exists
local file = io.open(source_fname)
if not file then
return_not_found()
end
file:close()
local dest_fname = cache_dir .. path
-- resize the image
os.execute("/usr/local/var/www/manga/manga.out " .. source_fname .. ' ' .. dest_fname);
ngx.exec(ngx.var.request_uri)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment