image_filter_jpeg_quality based on size

Quintin Par quintinpar at gmail.com
Wed Mar 21 02:40:37 UTC 2012


Thanks Appa.



On Tue, Mar 20, 2012 at 2:38 PM, Antonio P.P. Almeida <appa at perusio.net>wrote:

> > Let me rephrase my Q :-)
> >
> > Can I find out the file size in a location directive?
> > -Quintin
>
> Using set_by_lua (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)';
> }
>
> Untested. This will give you the file size on the variable $img_file_size.
>
>
> --appa
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20120321/48618905/attachment.html>


More information about the nginx mailing list