Skip to content
Node.js client for the Abraia API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images
test
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
abraia.js
client.js
config.js
package-lock.json
package.json

README.md

Npm Version Build Status Coverage Status

Abraia API client for Node.js

Node.js client for Abraia services. It is used to smartly optimize images for web. Every image is analyzed to choose the best image compression parameters for ecommerce and web optimization (best image quality with the minimal files size).

Installation

Install the API client:

npm install --save abraia

Get your free API key and set the ABRAIA_KEY environment variable every time you start a terminal/console session. On Windows, use set instead of export.

export ABRAIA_KEY=your_api_key

For a persistent configuration use your system options to set your ABRAIA_KEY.

Optimizing images

Using the fluent API, to optimize your images you just need to specify the input and output file name, and the image will be smartly optimized for a web best performance.

const abraia = require('abraia/abraia')

abraia.fromFile('images/lion.jpg').toFile('images/optimized.jpg')

For instance, the previous code significantly reduces the JPEG image file size from 470kB to 264kB using our content-aware compression algorithm.

You can also optimize PNG, GIF and WebP images, or convert them from one format to another just changing the file name extension.

abraia.fromFile('images/jaguar.png').toFile('images/jaguar8.png')
abraia.fromFile('images/jaguar.png').toFile('images/jaguar.jpg')

PNG jaguar PNG8 jaguar JPEG jaguar

This automatically optimizes the PNG image from 45KB to 15.8KB or convert it to JPEG (14.1KB) with a white background replacing the transparent one.

Resizing and cropping images

Moreover, Abraia services implement high quality resize and smart cropping options. You can automatically resize and crop your images just specifying the demanded image size.

abraia.fromFile('images/tiger.jpg')
  .resize({ width: 333, height: 333 })
  .toFile('images/tiger_333x333.jpg')

Resized tiger image Smart cropped tiger

Tiger image smart cropped to a square of 333x333 pixels

For a typical image resizing you just need to specify the width or the height of the final image.

abraia.fromFile('images/tiger.jpg')
  .resize({ height: 333 })
  .toFile('images/tiger_x333.jpg')

Resized tiger image

Tiger image resized to a height of 333 pixels

License

This software is licensed under the MIT License. View the license.

You can’t perform that action at this time.