Skip to content

Instantly share code, notes, and snippets.

@tumtumtum
Created February 17, 2015 10:52
Show Gist options
  • Save tumtumtum/b1f660a06affd395bb27 to your computer and use it in GitHub Desktop.
Save tumtumtum/b1f660a06affd395bb27 to your computer and use it in GitHub Desktop.
location /image/ {
# Support 100w100h and w100h100
rewrite ^\/image\/([^\/]+)\/w(\d+)$ /image/$1/$2w;
rewrite ^\/image\/([^\/]+)\/h(\d+)$ /image/$1/$2h;
rewrite ^\/image\/([^\/]+)\/w(\d+)\/h(\d+)$ /image/$1/$2w/$3h;
rewrite ^\/image\/([^\/]+)\/([^\/]+)\/w(\d+)$ /image/$1/$2/$3w;
rewrite ^\/image\/([^\/]+)\/([^\/]+)\/h(\d+)$ /image/$1/$2/$3h;
rewrite ^\/image\/([^\/]+)\/([^\/]+)\/w(\d+)\/h(\d+)$ /image/$1/$2/$3w/$4h;
# Support direct access
rewrite ^\/image\/(..)(..)([^\/\.]+)((\.|\/)jpeg)$ /ResizedImage/orig/$1/$2/$1$2$3.jpeg;
rewrite ^\/image\/(..)(..)([^\/\.]+)((\.|\/)png)$ /ResizedImage/orig/$1/$2/$1$2$3.png;
rewrite ^\/image\/(..)(..)([^\/\.]+)((\.|\/)gif)$ /ResizedImage/orig/$1/$2/$1$2$3.gif;
# Support resized URLs
rewrite ^\/image\/(..)(..)([^\/\.]+)(\.(jpeg|jpg))?(\/(jpeg|jpg))?(?:\/(\d+w))?(?:\/(\d+h))?$ /ResizedImage/$8$9/$1/$2/$1$2$3.jpeg;
rewrite ^\/image\/(..)(..)([^\/\.]+)(\.(png))?(\/(png))?(?:\/(\d+w))?(?:\/(\d+h))?$ /ResizedImage/$8$9/$1/$2/$1$2$3/$1$2$3.png;
rewrite ^\/image\/(..)(..)([^\/\.]+)(\.(gif))?(\/(gif))?(?:\/(\d+w))?(?:\/(\d+h))?$ /ResizedImage/$8$9/$1/$2/$1$2$3/$1$2$3.gif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment