https://github.com/turbokirichenko/image-serve
Openresty service for image processing using the imagick library
https://github.com/turbokirichenko/image-serve
imagick lua openresty resty
Last synced: 2 months ago
JSON representation
Openresty service for image processing using the imagick library
- Host: GitHub
- URL: https://github.com/turbokirichenko/image-serve
- Owner: turbokirichenko
- Created: 2024-04-24T15:47:35.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-24T15:57:39.000Z (about 1 year ago)
- Last Synced: 2025-01-21T22:35:07.067Z (4 months ago)
- Topics: imagick, lua, openresty, resty
- Language: Lua
- Homepage: https://github.com/turbokirichenko/image-serve/blob/main/README.md
- Size: 22.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Openresty service to serve images
It is a simple reverse proxy server for image processing
## Key Purposes
- Provide the fast way to edit images from the external source
- Minimise size of the image
- Change image extention
- Chenge default dimention of image
## Deploy
NOTE: Recommended to use deployment via Dockerfile
```bash
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
```
## Usage
First of all encode the url of a static resource in base64 encoding:
```bash
$ echo -n 'https://avatars.githubusercontent.com/u/92226824?v=4' | base64
# aHR0cDovL2ltYWdlc291cmNlL25hbWUuanBn
```
Now you can interract with the service by simply API:
```js
/** HTTP GET /image//?...
*
* @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:
```bash
$ 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
```
Result:

## Mime Types
There are available Mime Types:
```lua
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',
}
```
## ERROR
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'!
## LOGS
- Access: /var/log/nginx/amedia.log
- Error: /var/log/nginx/error.log
## TODO
- ENV variables
- E2E tests
- To increase the number of commands
- CLI version