All Projects → cubicdaiya → Ngx_small_light

cubicdaiya / Ngx_small_light

Licence: other
Dynamic Image Transformation Module For nginx.

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Ngx small light

Php Legofy
Transform your images as if they were made out of LEGO bricks.
Stars: ✭ 161 (-63.98%)
Mutual labels:  imagemagick, gd
Wasm Imagemagick
Webassembly compilation of https://github.com/ImageMagick/ImageMagick & samples
Stars: ✭ 442 (-1.12%)
Mutual labels:  imagemagick
Nginx Ui
Nginx UI allows you to access and modify the nginx configurations files without cli.
Stars: ✭ 4,067 (+809.84%)
Mutual labels:  nginx
Vue2 blog
使用vue2.x + vue-cli +vue-router+ vuex + axios + mysql + express + pm2 + webpack+nginx构建的具有登录,注册,留言,用户发帖,用户评论等功能的SPA Blog。注意,注意,注意,后端API全部自己手写,很适合刚学习vue以及express的小伙伴学习,喜欢请Star鼓励一下我,谢谢!项目预览:
Stars: ✭ 417 (-6.71%)
Mutual labels:  nginx
Ngx aws auth
nginx module to proxy to authenticated AWS services
Stars: ✭ 397 (-11.19%)
Mutual labels:  nginx
Ssl Proxy
🔒 Simple zero-config SSL reverse proxy with real autogenerated certificates (LetsEncrypt, self-signed, provided)
Stars: ✭ 427 (-4.47%)
Mutual labels:  nginx
Highdsa
2018年本科毕设项目,已更新所有开发和部署文档。基于Dubbo、SSM、Shiro、ELK、ActiveMQ、Redis等实现的一套高可用、高性能、高可扩展的分布式系统架构,实现可支持业务的基础公共服务,API使用Restful风格对外暴露。已经实现的包括:发送邮件服务、FastDFS文件存储服务、ELK实时日志查询服务、Redis缓存服务、Mybatis数据库、阿里短信推送、Goeasy消息推送、Druid监控、ActiveMQ消息队列、shiro权限认证、cas单点登录、权限配置web系统、移动端后台系统。持续更新中......
Stars: ✭ 385 (-13.87%)
Mutual labels:  nginx
Ngx waf
A web application firewall module for nginx without complex configuration. & 使用简单的 nginx 防火墙模块
Stars: ✭ 444 (-0.67%)
Mutual labels:  nginx
Govips
A lightning fast image processing and resizing library for Go
Stars: ✭ 442 (-1.12%)
Mutual labels:  imagemagick
Docker Laravel
🐳 Build a simple laravel development environment with docker-compose.
Stars: ✭ 415 (-7.16%)
Mutual labels:  nginx
Nginx Tutorial
最全面,最深入的nginx从入门到精通的教程
Stars: ✭ 416 (-6.94%)
Mutual labels:  nginx
Nginx Openresty Windows
nginx for windows with openresty
Stars: ✭ 404 (-9.62%)
Mutual labels:  nginx
Ansible Playbooks
Ansible playbook collection that have been written for Ubuntu. Some of the playbooks are Elasticsearch, Mesos, AWS, MySql, Sensu, Nginx etc..
Stars: ✭ 429 (-4.03%)
Mutual labels:  nginx
Django React Boilerplate
DIY Django + React Boilerplate for starting your SaaS
Stars: ✭ 385 (-13.87%)
Mutual labels:  nginx
Mogrify
Image processing in Elixir (ImageMagick command line wrapper)
Stars: ✭ 442 (-1.12%)
Mutual labels:  imagemagick
Naxsi
NAXSI is an open-source, high performance, low rules maintenance WAF for NGINX
Stars: ✭ 3,927 (+778.52%)
Mutual labels:  nginx
Crossplane
Quick and reliable way to convert NGINX configurations into JSON and back.
Stars: ✭ 407 (-8.95%)
Mutual labels:  nginx
Awesome Nginx Security
🔥 A curated list of awesome links related to application security related to the environments with NGINX or Kubernetes Ingres Controller (based on NGINX)
Stars: ✭ 417 (-6.71%)
Mutual labels:  nginx
Nginx Autoinstall
Compile Nginx from source with custom modules on Debian and Ubuntu
Stars: ✭ 443 (-0.89%)
Mutual labels:  nginx
Ezhttp
The bash shell script stack for installation of Nginx OpenResty Tengine lua_nginx_module nginx_concat_module nginx_upload_module ngx_substitutions_filter_module Apache-2.2 Apache-2.4 MySQL-5.1 MySQL-5.5 MySQL-5.6 MySQL-5.7 PHP-5.2 PHP-5.3 PHP-5.4 PHP-5.5 PHP-5.6 ZendOptimizer ZendGuardLoader Xcache Eaccelerator Imagemagick IonCube Memcache Memcached Redis Mongo Xdebug Mssql Memcached PureFtpd PhpMyAdmin Redis Mongodb PhpRedisAdmin MemAdmin RockMongo Jdk7 Jdk8 Tomcat7 Tomcat8
Stars: ✭ 443 (-0.89%)
Mutual labels:  nginx

ngx_small_light

A dynamic image transformation module for nginx.

Table of contents

Features

Supports the various image-processings below.

  • Resize
  • Rotate
  • Sharpen
  • Unsharpen
  • Blur
  • Border
  • Canvas
  • Crop
  • Composition
  • JPEG Hinting(except GD)
  • Format convert(e.g. PNG -> JPEG)
  • Color-space convert(e.g. CMYK -> sRGB)

ngx_small_light is developed for using as the same way as mod_small_light as possible in nginx.

Supported Formats

Supports the formats below.

  • JPEG
  • GIF(except Imlib2)
  • PNG
  • WebP(except Imlib2)

Dependencies

Installation

cd ${ngx_small_light_src_dir}
./setup
cd {$nginx_src_dir}
./configure --add-module=${ngx_small_light_src_dir}
make
make install

If you want to enable the libraries except ImageMagick in ngx_small_light, add the options below when executing setup. (ImageMagick is always enabled)

./setup                         # enable ImageMagick
./setup --with-imlib2           # enable ImageMagick and Imlib2
./setup --with-gd               # enable ImageMagick and GD
./setup --with-imlib2 --with-gd # enable ImageMagick and Imlib2 and GD

Dynamic module

You can also compile ngx_small_light as the dynamic module with --add-dynamic-module in nginx-1.9.11 and ngx_small_light-0.6.15 or later.

cd ${ngx_small_light_src_dir}
./setup
cd {$nginx_src_dir}
./configure \
--modules-path=/usr/local/nginx/modules \
--add-dynamic-module=${ngx_small_light_src_dir}
make
make install

Add the configuration below for loading module dynamically.

load_module /usr/local/nginx/modules/ngx_http_small_light_module.so;

Getting started

Add the configuration below to some server context in nginx.conf and start nginx.

small_light on;
location ~ small_light[^/]*/(.+)$ {
    set $file $1;
    rewrite ^ /$file;
}

If you can get the original image of image.jpg from the URL below,

http://$host:$port/img/image.jpg

You will be able to get the converted image of image.jpg from the URL below.

http://$host:$port/small_light(dw=300,dh=300)/img/image.jpg

The part of small_light(...) is called small_light function.

Configuration example

There is some configuration example below.

server {
    listen 8000;
    server_name localhost;

    small_light on;
    small_light_pattern_define msize dw=500,dh=500,da=l,q=95,e=imagemagick,jpeghint=y;
    small_light_pattern_define ssize dw=120,dh=120,da=l,q=95,e=imlib2,jpeghint=y;

    # http://localhost:8000/small_light(p=msize)/img/filename.jpg -> generate msize image
    # http://localhost:8000/small_light(p=ssize)/img/filename.jpg -> generate ssize image
    # http://localhost:8000/small_light(of=gif,q=100)/img/filename.jpg -> generate gif image which quality is 100
    location ~ small_light[^/]*/(.+)$ {
        set $file $1;
        rewrite ^ /$file;
    }
} 

Directives

small_light

Syntax small_light on | off
Default off
Context server, location

This directive sets whether image-processing with ngx_small_light is enabled in a server context.

small_light_getparam_mode

Syntax small_light_getparam_mode on | off
Default off
Context server, location

This directive sets whether converting-image is enabled by GET parameters instead of small_light function (e.g. /small_light(dw=200,dh=200)). At the expense of it, a small_light function is disabled. But you need to set both small_light and small_light_getparam_mode on to enable the feature of this directive.

small_light_material_dir

Syntax small_light_material_dir path
Default
Context server

This directive assigns the directory for embedded icon images.

small_light_pattern_define

Syntax small_light_pattern_define pattern_name parameters
Default
Context server

This directive names comma-delimited parameters.

small_light_radius_max

Syntax small_light_radius_max number
Default 10
Context server,location

This directive sets maximum radius value of geometry for sharpen and unsharp and blur.

small_light_sigma_max

Syntax small_light_sigma_max number
Default 10
Context server,location

This directive sets maximum sigma value of geometry for sharpen and unsharp and blur.

small_light_imlib2_temp_dir

Syntax small_light_imlib2_temp_dir path [level1 [level2 [level 3 ]]]
Default small_light_imlib2_temp 1 2
Context server

This directive assigns the directory for temporary file for Imlib2 processing. This directive is available when Imlib2 is enabled.

small_light_buffer

Syntax small_ligh_buffer size
Default 1m
Context server

This directive assigns the maximum size of the buffer used for reading images when Content-Length is not set in response headers.

Parameters for small_light function

Parameter Type Default Description ImageMagick Imlib2 GD
p string named pattern of comma-delimited parameters ⭕️ ⭕️ ⭕️
e string imagemagick engine name (imagemagick, imlib2, gd)
q number quality ⭕️ ⭕️ ⭕️
of string output format (jpg, gif, png, webp) ⭕️ ⭕️ ⭕️
jpeghint char n enable jpeg hinting (y, n) ⭕️ ⭕️
dw coord sw destination width ⭕️ ⭕️ ⭕️
dh coord sh destination height ⭕️ ⭕️ ⭕️
dx coord sx destination x coordinate ⭕️ ⭕️ ⭕️
dy coord sy destination y coordinate ⭕️ ⭕️ ⭕️
da char l destination aspect ratio contol (l, s, n) ⭕️ ⭕️ ⭕️
ds char n destination scaling control (s, n) ⭕️ ⭕️ ⭕️
cw number canvas width ⭕️ ⭕️ ⭕️
ch number canvas height ⭕️ ⭕️ ⭕️
cc color 000000 canvas color ⭕️ ⭕️ ⭕️
bw number border width ⭕️ ⭕️ ⭕️
bh number border height ⭕️ ⭕️ ⭕️
bc color 000000 border color ⭕️ ⭕️ ⭕️
sw coord source witdh ⭕️ ⭕️ ⭕️
sh coord source height ⭕️ ⭕️ ⭕️
sx coord source x coordinate ⭕️ ⭕️ ⭕️
sy coord source y coordinate ⭕️ ⭕️ ⭕️
pt char n pass through control (y, n) ⭕️ ⭕️ ⭕️
sharpen string radius,sigma (e.g. 10x5) ⭕️ ⭕️ ⭕️
unsharp string radius,sigma,amount,threshold (e.g 2x5+0.5+0) ⭕️
blur string radius,sigma (e.g. 5x10) ⭕️ ⭕️
embedicon string embedded icon file in small_light_material_dir ⭕️
ix number 0 embedded icon x coordinate ⭕️
iy number 0 embedded icon y coordinate ⭕️
angle number 0 angle of rotation (90, 180, 270) ⭕️ ⭕️ ⭕️
progressive char n make JPEG progressive (y, n) ⭕️
cmyk2rgb char n convert colorspace from CMYK to sRGB (y, n) ⭕️
rmprof char n remove profile (y, n) ⭕️
autoorient char n enable adjust image orientation automatically (y, n) ⭕️

The values of da are l and s and n. These present the meanings below.

  • l: long-edge based
  • s: short-edge based
  • n: nope

There are any limitations below.

  • of=gif and of=webp are not supported when e=imlib2.
  • autoorient is available ImageMagick-6.9.0 or later.
  • The value of radius,sigma for sharpen and unsharp and blur is limited by small_light_radius_max and small_light_sigma_max.

There are the types of each parameter below.

Type Description
coord coordicante or pixel. percent when appending 'p'
char character
number integer number
color rrggbb or rrggbbaa
string string

Named Pattern

ngx_small_light supports to name comma-delimited parameters with the small_light_define_patern.

small_light_pattern_define small dw=120,dh=120,q=80,e=imagemagick,jpeghint=y;

If the line above is added to some server context in nginx.conf, the two URLs below return same response.

  • http://$host:$port/small_light(p=small)/img/image.jpg
  • http://$host:$port/small_light(dw=120,dh=120,q=80,e=imagemagick,jpeghint=y)/img/image.jpg

Using GET parameters

ngx_small_light supports to convert image not only by small_light function but by GET paramenters in v0.5.0 or later. You need to set both small_light and small_light_getparam_mode on to enable this feature. At the expense of enabling this feature, small_light function (e.g. /small_light(dw=300,dh=300)/img.jpg is disabled.

small_light on;
small_light_getparam_mode on;

In the configuration above, the url below does not return converted image.

http://localhost:8000/small_light(dw=200,dh=200)/img/image.jpg

Instead the url below returns converted image expected by right.

http://localhost:8000/img/image.jpg?dw=200&dh=200

Enabling WebP Transformation

ngx_small_light supports WebP transformation with ImageMagick and GD. Given of=webp to small_light function, ngx_small_light transforms image format into WebP. But ImageMagick requires libwebp and GD requires libvpx. You need to embed these libraries in building ImageMagick and GD for enabling WebP transformation.

If WebP transformation is not available, nginx outputs the line like below in error.log in processing image with of=webp.

WebP is not supported

If WebP transformation with ImageMagick is available, the output of convert -list format includes the line like below.

$ convert -list format | grep -i webp
     WEBP* WEBP      rw-   WebP Image Format (libwebp 0.5.0[0208])

If WebP transformation with GD is available, the output of gdlib-config --libs includes -lvpx.

In general, the packages of ImageMagick and GD provided from the linux distributions such as Ubuntu and CentOS does not embed the library for WebP transformation by default. In such cases, you need to build ImageMagick or GD yourself.

Optimizing Tips

There are some optimizing tips for ngx_small_light.

JPEG hinting

When the output format is JPEG and image-converting engine is ImageMagick or Imlib2, you may give jpeghint=y. The speed of processing images is improved dramatically.

Limit thread-number with OpenMP

When image-converting engine is ImageMagick and the version of ngx_small_light is lower than v0.6.14, giving 1 to OMP_NUM_THREADS or MAGICK_THREAD_LIMIT in nginx.conf is recommended strongly. Because OpenMP is enabled in ImageMagick by default and ImageMagick enabled OpenMP is very slow on multi-process environment.

env OMP_NUM_THREADS=1; # or env MAGICK_THREAD_LIMIT=1;

Or you can avoid this problem by building ImageMagick with --disable-openmp.

In v0.6.14 or later, they are no longer required. Because ngx_small_light always sets the thread-number with OpenMP 1.

Limitations

ngx_small_light has the limitations below.

Not supported features with Imlib2

The transformation with Imlib2 does not support to write GIF-image. Because Imlib2 has the function for loading GIF-image but does not have the function for saving. Additionally, the transformation by Imlib2 does not support to write and read WebP-image. So of=gif and e=imlib2 are not enabled to specify at once. If these are specified, ngx_small_light returns 415(Unsupported Media Type).

Not supported features with GD

The transformation with GD supports to write WebP-image. But it is the experimental feature.

Not supported animated GIF

ngx_small_light does not support the transformation kept animation for animated GIF. Because it takes long time to transform(e.g. resize, crop) animated GIF kept animation. So it is not realistic for ngx_small_light to support an animated GIF.

If the animated GIF is given, ngx_small_light transforms only the first frame.

Running Tests

perl Build.PL
cpanm --installdeps .
NGINX_BIN=${nginx_prefix_dir}/sbin/nginx ./Build test
# or
NGINX_BIN=${nginx_prefix_dir}/sbin/nginx prove t/**/*.t

License

Please read the COPYING.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].