Skip to content
/ hikaru Public

Nginx / LUA / ImageMagick - based seo-friendly lightweight thumbnail server

Notifications You must be signed in to change notification settings

Urvin/hikaru

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hikaru thumbnail server

Nginx / LUA / ImageMagick - based seo-friendly lightweight thumbnail server

Requirements

Installation

  • Install common tools
# nginx with lua
sudo apt-get install nginx-extras

# lua-imagick requirements
sudo apt-get install libluajit-5.1-dev
sudo apt-get install cmake
sudo apt-get install g++
sudo apt-get install imagemagick
sudo apt-get install libmagickwand-dev

# own requirements
sudo apt-get install luarocks
sudo luarocks install bit32
sudo apt-get install webp
  • Build Lua Imagick as described in it's readme
  • Update settings src/hikaru_config.lua
  • Configure src/nginx.conf as you need
  • Add Hikaru part into your nginx server config
sudo ls -s /path/to/hikaru/nginx.conf /etc/nginx/sites-enabled/hikaru

Usage

Upload image

Make a PUT request with body containing image data to /upload/your_image_name Server responses a 201/Created status in success

Via curl:

curl -i http://hikaru.local/upload/test_image --upload-file /path/to/local/image.jpg

Get thumbnail

Define your image width and height If you want to get an image with 200px width and no matter height, set height to 0. Thumbnailer will calculate it using original image aspect ratio. The same works with width. If you set to 0 both params, the source width and height will be used.

Define cast flag The resulting cast flag should be an integer, obtained via bitwise OR among available cast flags.

Calculate security signature Signature is a md5 hash of concatenated stings of salt, width, height, cast, filename without extension

# salt = secretsalt
# with = 100
# height = 200
# cast = 8
#filename = test_image.jpg
echo -n secretsalt1002008test_image | md5sum

Define desired thumbnail format Note that Hikaru sends WEBP format to browser accepting image/webp regardless your extension.

Combine parts of your URL Request /signature/widthxheight/cast/filename.extension one

wget http://hikaru.local/07b58ae7ccbd896f85c39a5cd4eb06ec/100x150/4/test_image.jpg

Cast flags

  • CAST_RESIZE_TENSILE = 2 - stretch image directly into defined width and height ignoring aspect ratio
  • CAST_RESIZE_PRECISE = 4 - keep aspect-ratio, use higher dimension
  • CAST_RESIZE_INVERSE = 8 - keep aspect-ratio, use lower dimension
  • CAST_TRIM = 16 - remove any edges that are exactly the same color as the corner pixels
  • CAST_EXTENT = 32 - set output canvas exactly defined width and height after image resize
  • CAST_OPAGUE_BACKGROUND = 64 - set image white opaque background

Remove image

Make a DELETE request to /remove/your_image_name. Hikaru removes both source and thumbnail files. Server responses a 200/Ok status in success.

Via curl:

curl -i http://hikaru.local/remove/test_image

Robots.txt

Hikaru provides valid seo-friendly robots.txt

curl http://hikaru.local/robots.txt

Clients

Author

Yuriy Gorbachev yuriy@gorbachev.rocks

License

This module is licensed under the GLWTPL license.

About

Nginx / LUA / ImageMagick - based seo-friendly lightweight thumbnail server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages