1.0.1 • Published 8 years ago

imapi v1.0.1

Weekly downloads
1
License
ISC
Repository
-
Last release
8 years ago

imAPI

This is an image service with on the fly resize, filling, fitting capabilities. The service always keep aspect ratio of image, thus filling to a given size will scale + crop to avoid deformation.

All returned images can be cached on the server if redis is available (recommended), and HTTP caching (Cache-Control header is filled properly) information is always sent for proper handling by the client (usually a browser).

Upload an image

$ curl -F "image=@image.jpg" http://<imapiHost>/images

{
  "id":"2b864a3c4e8e33b96d0dde5166f53cb4",
  "width":200,
  "height":150,
  "format":"jpeg",
  "space":"srgb",
  "channels":3,
  "hasAlpha":false,
  "url":"http://<imapiHost>/images/2b864a3c4e8e33b96d0dde5166f53cb4"
}

Get an image

All modes will output the image in the same format as the originally uploaded image. If JPG was uploaded then JPG is given back to you. You can change this by querying a different format with ?format=png or ?format=jpg

Supported queries

  • mode: original (default) | fill | fit
  • width: not specified = same as original | integer
  • height: not specified = same as original | integer
  • format: not specified = same as original | jpg | png
  • background: default to rgba(0,0,0,255)
  • sharpen: false (default) or true | on

background is used when performing a fit operation, to select the background color. It is alos used when asking for JPG format when the source was PNG with transparent background, to select the new background color. It hence flatten the image.

Original image

http://<imapiHost>/images/2b864a3c4e8e33b96d0dde5166f53cb4

npm.io

Fill to a given width (keep aspect ratio)

http://<imapiHost>/images/2b864a3c4e8e33b96d0dde5166f53cb4?width=100&mode=fill

npm.io

Fill to a given height (keep aspect ratio)

http://<imapiHost>/images/2b864a3c4e8e33b96d0dde5166f53cb4?height=50&mode=fill

npm.io

Fill to a given size

http://<imapiHost>/images/2b864a3c4e8e33b96d0dde5166f53cb4?height=100&width=100&mode=fill

npm.io

Fit to a given rectangle

http://<imapiHost>/images/2b864a3c4e8e33b96d0dde5166f53cb4?height=100&width=100&mode=fit&background=rgb(255,0,0)

npm.io