image_filter enhancement

Maxim Dounin mdounin at mdounin.ru
Tue Dec 18 10:53:41 UTC 2012


Hello!

On Sun, Dec 16, 2012 at 07:55:39PM +0400, ivan babrou wrote:

> On 5 December 2012 18:52, Maxim Dounin <mdounin at mdounin.ru> wrote:
> 
> > Hello!
> >
> > On Tue, Dec 04, 2012 at 06:58:17PM +0400, ivan babrou wrote:
> >
> > > >
> > > > Additionally, looking at the code I tend to think it's incorrect.
> > > > That is, it's pattern you've followed is incorrect, not your code.
> > > > E.g. the following config will result in $arg_q incorrectly used
> > > > for quality in /image/, instead of "80" explicitly set:
> > > >     image_filter_jpeg_quality $arg_q;
> > > >     location /image/ {
> > > >         image_filter crop $arg_w $arg_h;
> > > >         image_filter_jpeg_quality 80;
> > > >     }
> > > > This needs fixing.
> > >
> > >
> > > As I see other config variables are buggy too. Should I fix them too?
> >
> > It would be fine to produce a patch which fixes existing config
> > variables, and the patch to add crop offsets on top of it.
> 
> 
> Can you give me some good examples to see "good practices" in nginx
> configuration handling?

I would recommend looking into standard ngx_conf_merge_*_value() 
macros from src/core/ngx_conf_file.h, and rolling your code based 
on them with needed modifications and/or code reuse.  Something 
like this should work:

    if (conf->jpeg_quality == NGX_CONF_UNSET_UINT) {
        ngx_conf_merge_uint_value(conf->jpeg_quality, prev->jpeg_quality, 75);

        if (conf->jqcv == NULL) {
            conf->jqcv = prev->jqcv;
        }
    }

-- 
Maxim Dounin
http://nginx.com/support.html



More information about the nginx-devel mailing list