超好用的图片处理工具,可配合minio实现如阿里云的图片处理查询
|
8 years ago | |
---|---|---|
examples | 8 years ago | |
vendor | 8 years ago | |
.dockerignore | 8 years ago | |
.gitignore | 8 years ago | |
Dockerfile | 8 years ago | |
LICENSE | 8 years ago | |
README.md | 8 years ago | |
config.go | 8 years ago | |
crypt.go | 8 years ago | |
download.go | 8 years ago | |
glide.lock | 8 years ago | |
glide.yaml | 8 years ago | |
main.go | 8 years ago | |
process.go | 8 years ago | |
server.go | 8 years ago |
Fast and secure microservice for resizing and converting remote images.
Imgproxy does one thing, and it does it well: resizing of remote images. It works great when you need to resize some images on the fly to make them look good on your web page. The main principles of Imgproxy are simplicity, speed, and security.
One of the things I believe in is: "The best feature is the one you don't need to implement." That's why I implemented only features that most of us need.
Imgproxy uses probably the most efficient image processing library - libvips. It's fast and requires low memory footprint. Thus it allows processing a massive amount of images on the fly.
Also, imgproxy uses native Go's net/http routing for an absolute speed.
Processing of remote images is a quite vulnerable thing. There are many ways to attack you, so it's a good idea to take measures to prevent attacks. There is what imgproxy does:
It checks image type and dimensions while downloading, so the image won't be fully downloaded if it has an unknown format or too big dimensions. Thus imgproxy protects you from image bombs like https://www.bamsoftware.com/hacks/deflate.html
Imgproxy protects its URL path with a signature, so it can't be easily compromised by an attacker. Thus imgproxy doesn't allow to use itself by third-party applications.
Imgproxy supports authorization by HTTP header. This prevents using imgproxy directly by an attacker but allows to use it through CDN or a caching server.
There are two ways you can currently install imgproxy:
Install vips
# macOS
$ brew tap homebrew/science
$ brew install vips
# Ubintu
$ sudo apt-get install libvips
Install imgproxy itself
$ go get github.com/DarthSim/imgproxy
$ docker build -t imgproxy .
Imgproxy is 12factor-ready and can be configured with env variables.
Imgproxy requires all paths to be signed with key and salt:
You can also specify paths to a files with hex-encoded key and salt (useful in a development evironment):
$ imgproxy -keypath /path/to/file/with/key -saltpath /path/to/file/with/salt
You can easily generate random key/salt with xxd -g 2 -l 64 -p /dev/random | tr -d '\n'
.
Imgproxy protects you from image bombs. Here you can specify maximum image dimension which you're ready to process:
Also you can specify secret to enable authorization with HTTP Authorization
header:
Authorization: Bearer %secret%
header;Url path should contain signature and resizing params like this:
/%signature/%resizing_type/%width/%height/%gravity/%enlarge/%encoded_url.%extension
Imgproxy supports the following resizing types:
fit
- resizes image keeping aspect ratio to fit given size;fill
- resizes image keeping aspect ratio to fill given size and crops projecting parts;crop
- crops image to given size;force
- resizes image to given size breaking aspect ratio.Width and height define size of the result image. The result dimensions may be not equal to the given depending on what resizing type was applied.
When imgproxy needs to cut some parts of the image, it's guided by gravity. The following values are supported:
no
- north (top edge);so
- south (bottom edge);ea
- east (right edge);we
- west (left edge);ce
- center;sm
- smart. Vips detects the most interesting section of the image and considers it as the center of the result image. Note: This value applicable only to the crop resizing.This param is 0
, imgproxy won't enlarge image if it's smaller that given size. With any other value imgproxy will enlarge image.
The source url should be encoded with url-safe base64. Encoded url can be splitted with /
for your needs.
Extension specifies the format of the result image. Imgproxy supports only jpg
and png
as the most popular web-image formats.
Signature is a url-safe base64-encoded HMAC digest of the rest of the path including leading /
.
/%resizing_type/%width/%height/%gravity/%enlarge/%encoded_url.%extension
;You can find code snippets in the examples
folder.
Imgproxy supports only three most popular images formats: PNG, JPEG and GIF.
Known issue: Libvips may not support some kinds of JPEG, if you met this issue, you may need to build libvips with ImageMagick or GraphicMagick support. See https://github.com/jcupitt/libvips#imagemagick-or-optionally-graphicsmagick
Special thanks to h2non and all authors and contributors of bimg.
Sergey "DarthSim" Aleksandrovich
Imgproxy is licensed under the MIT license.
See LICENSE for the full license text.