Skip to content

Instantly share code, notes, and snippets.

@cuu
Created October 3, 2021 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuu/d541c1c955efdee1b88a2ed027e0678a to your computer and use it in GitHub Desktop.
Save cuu/d541c1c955efdee1b88a2ed027e0678a to your computer and use it in GitHub Desktop.
image_server nginx
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
# Original picture
location /image {
alias /home/guu/tmp/;
}
# thumbnail
location ~* /image/(.+)!(large|lg|tiny|banner|md|sm|xs)$ {
set $filename $1;
set $img_version $2;
set $img_type resize;
set $img_w -;
set $img_h -;
if ($img_version = 'large') {
set $img_type resize;
set $img_w 1920;
}
if ($img_version = 'lg') {
set $img_type crop;
set $img_w 192;
set $img_h 192;
}
if ($img_version = "tiny") {
set $img_type crop;
set $img_w 140;
set $img_h 140;
}
if ($img_version = "banner") {
set $img_type crop;
set $img_w 750;
set $img_h 300;
}
if ($img_version = 'md') {
set $img_type crop;
set $img_w 96;
set $img_h 96;
}
if ($img_version = 'sm') {
set $img_type crop;
set $img_w 48;
set $img_h 48;
}
if ($img_version = 'xs') {
set $img_type crop;
set $img_w 32;
set $img_h 32;
}
rewrite ^ /_$img_type;
}
# Processing of Scaled Pictures
location /_resize {
alias /home/guu/tmp/$filename;
image_filter resize $img_w $img_h;
image_filter_jpeg_quality 95;
image_filter_buffer 20M;
image_filter_interlace on;
}
# Processing of clipped pictures
location /_crop {
alias /home/guu/tmp/$filename;
image_filter crop $img_w $img_h;
image_filter_jpeg_quality 95;
image_filter_buffer 20M;
image_filter_interlace on;
}
}
@cuu
Copy link
Author

cuu commented Oct 3, 2021

@cuu
Copy link
Author

cuu commented Oct 3, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment