@ligadigital/image-resizer

Resize images on the fly

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
@ligadigital/image-resizer
Minified + gzip package size for @ligadigital/image-resizer in KB

Readme

Image Resizer

Build Status node NpmLicense npm (scoped)

Usage

GET /:mode/:size/:path

Modes

Must be one of the following:

  • resize
  • crop
  • resizefit
  • resizefitgray
  • shrink

Size

Must be in one of the following formats:

  • 100x100 (width and height)
  • 100x (width only)
  • x100 (height only)

Examples

GET /crop/100x100/example.org/my-image.jpeg

S3

If a S3 bucket is configured the process works like this:

  • Request app requests image from S3 bucket
  • If the image does not exist, S3 redirects to the image-resizer
    • ln-image-resizer resizes the image un puts it on S3
    • ln-image-resizer redirects back to S3
  • If the image exist, S3 serves the image

Example s3 Routing rule

<RoutingRules>
  <RoutingRule>
    <Condition>
      <KeyPrefixEquals>image-resizer/</KeyPrefixEquals>
      <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
    </Condition>
    <Redirect>
      <Protocol>https</Protocol>
      <HostName>example.org</HostName>
      <ReplaceKeyPrefixWith>image-resizer/</ReplaceKeyPrefixWith>
      <HttpRedirectCode>302</HttpRedirectCode>
    </Redirect>
  </RoutingRule>
</RoutingRules>

Configureation

All configuration is done via enviroment variables:

  • S3_BUCKET (e.g. ligacloud-ligaos-test-static)
  • S3_PATH" (e.g. ln-image-resizer)
  • S3_URL (e.g. http://ligacloud-ligaos-test-static.s3-website.eu-central-1.amazonaws.com)
  • S3_ACCESS_KEY_ID
  • S3_SECRET_ACCESS_KEY

Dependencies

On Mac:

brew install imagemagick
brew install graphicsmagick
brew install gifsicle

TODOs

  • Make tmp/ dir configurable
  • Docker container
  • Better documentation
  • Drop node 4 support

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.