Image_filter_jpeg_quality based on size

Hi all,

In the --with-http_image_filter_module:

Can I set image_filter_jpeg_quality based on image size? Say I want to
apply a loss of 75 to all images greater than 400KB. For the rest do
nothing.

-Quintin

Let me rephrase my Q :slight_smile:

Can I find out the file size in a location directive?
-Quintin

Let me rephrase my Q :slight_smile:

Can I find out the file size in a location directive?
-Quintin

Using set_by_lua (Lua | NGINX):

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

Thanks Appa.