Resize Image secara Dinamis via nginx

Ada 2 cara memasang nginx, yang pertama menggunakan repo dari nginx sesuai dengan petunjuk di tautan berikut:

http://nginx.org/en/linux_packages.html?_ga=1.7002802.1293912275.1489706695

Atau, Install modul extras di Ubuntu (menggunakan repo ubuntu):

sudo apt install nginx-extras

Tambahkan baris berikut di /etc/nginx/sites-available/default

location ~ ^/img([0-9]+)(?:/(.*))?$ {
        alias /path/to/images/dir/$2;
        image_filter_buffer 10M;
        image_filter resize $1 -;
    }

Restart nginx

sudo service nginx restart

Sekarang kita bisa mengubah ukuran gambar secara mudah hanya dengan menambahkan /imgxxx/ di depan path ke image asli, misal, path berikut berarti me-resize gambar ke ukuran 200:

/img200/assets/image.png

atau mengubah ke ukuran 75

/img75/assets/image.png

Referensi: dzone

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s