- Provide the fast way to edit images from the external source
- Minimise size of the image
- Change image extention
- Chenge default dimention of image
NOTE: Recommended to use deployment via Dockerfile
git clone http://github.com/turbokirichenko/static-serve.git
cd ./static-serve
docker buildx build --tag "static-serve" .
docker run -d -p 8082:8080 -n "image-service" static-serve
First of all encode the url of a static resource in base64 encoding:
$ echo -n 'https://avatars.githubusercontent.com/u/92226824?v=4' | base64
# aHR0cDovL2ltYWdlc291cmNlL25hbWUuanBn
Now you can interract with the service by simply API:
/** HTTP GET /image/<base64Url>/?...
*
* @param {string} base64url - is external image url in base64 encoding
* @param {string | undefined} ext - new extention of the image (see MIMIE TYPES...)
* @param {number | undefined} w - new width of the image
* @param {number | undefined} h - new height of the image
*
* NOTE: service will resize image proportionally!
*
*
* RESPONSE 200 OK
*/
NOTE: service will resize image proportionally!
Example:
$ curl -v -X GET "http://localhost:8082/image/aHR0cHM6Ly9hdmF0YXJzLmdpdGh1YnVzZXJjb250ZW50LmNvbS91LzkyMjI2ODI0P3Y9NA==?w
=200&ext=jpg" --output ./avatar.jpg
Note: Unnecessary use of -X or --request, GET is already inferred.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1:8082...
* Connected to localhost (127.0.0.1) port 8082 (#0)
> GET /image/aHR0cHM6Ly9hdmF0YXJzLmdpdGh1YnVzZXJjb250ZW50LmNvbS91LzkyMjI2ODI0P3Y9NA==?w=200&ext=avif HTTP/1.1
> Host: localhost:8082
> User-Agent: curl/7.75.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: openresty/1.21.4.1
< Date: Wed, 24 Apr 2024 15:35:26 GMT
< Content-Type: image/avif
< Content-Length: 1009
< Connection: keep-alive
<
{ [1009 bytes data]
100 1009 100 1009 0 0 2287 0 --:--:-- --:--:-- --:--:-- 2293
* Connection #0 to host localhost left intact
There are available Mime Types:
mime_types = {
apng = 'image/apng',
avif = 'image/avif',
gif = 'image/gif',
png = 'image/png',
jpg = 'image/jpg',
jpeg = 'image/jpg',
jfif = 'image/jpg',
pjpeg = 'image/jpg',
svg = 'image/svg+xml',
webp = 'image/webp',
bmp = 'image/bmp',
ico = 'image/x-icon',
cur = 'image/x-icon',
tif = 'image/tiff',
tiff = 'image/tiff',
}
You will get this image if the service returns an error:
To change default error image, just replace it from www/static/400.jpg
NOTE: to more imformation about an error see: '/var/log/nginx/error.log'!
- Access: /var/log/nginx/amedia.log
- Error: /var/log/nginx/error.log
- ENV variables
- E2E tests
- To increase the number of commands
- CLI version