Code Monkey home page Code Monkey logo

image-serve's Introduction

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

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:

$ 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

Result: result image

Mime Types

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',
}

ERROR

You will get this image if the service returns an error:

error image


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

image-serve's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.