0.0.1 • Published 11 months ago

imagify-nodejs v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Imagify NodeJS Client

A TypeScript based NPM package that follows the Imagify.io API docs.

API Key

You will need to create an account and get an API key from Imagify.

ENV Variables Needed

You will need to add the following ENV variables to your project for this to work.

API_URL='https://app.imagify.io/api'
API_KEY='your-api-key'

API Endpoints

The entire API consists of three API endpoints, two of which are related to sub-accounts. With a $10/month plan, you get unlimited image optimization. We are not going to worry about the subaccounts at this time.

Upload Endpoint /upload

Query Parameters

Query parameters should be send as a form-data request:

ParameterTypeDescription
imagebinaryYour image file * required
datajsonA json with optimization parameters
  • TS Interface:
interface ImageParams {
    image: any; // don't have a binary type
    data?: DataParams;
}

Data Parameters

By filling the data parameter you will be able to control the optimization and to resize images.

ParameterTypeDefaultDescription
normalboolfalseOptimization with a losseless algorithm
aggressivebooltrueOptimization with Agressive algorithm
ultraboolfalseOptimization with Ultra algorithm
keep_exifboolfalseWill allow you to preserve meta data in images
resizeboolfalseArray with resize paramater
resize“width”intfalseWill resize the image with the given width
resize“height”intfalseWill resize the image with the given height
resize“percentage”intfalseWill resize the image with the given percentage
  • TS Interface:
interface DataParams {
    normal?: boolean;
    aggressive?: boolean;
    ultra?: boolean;
    keep_exif?: boolean;
    resize?:
        | boolean
        | {
              width?: number;
              height?: number;
              percentage?: number;
          };
}

Expected Response

{
    "code": 200,
    "image": "http://storage.imagify.io/imagify/45dfi7h/1.jpg",
    "new_size": 100,
    "original_size": 200,
    "percent": 50,
    "success": true
}
  • TS Interface:
interface UploadResponse {
    code: number;
    image: string;
    new_size: number;
    original_size: number;
    percent: number;
    success: boolean;
}

Errors

Imagify API uses the following error codes:

Error CodeMeaning
400Bad Request – Your request was not understandable.
422Already compressed – Your image is already compressed.
403Forbidden – You don’t have the proper right to access the data.
404Not Found – The specified ressource could not be found.
405Method Not Allowed – You tried to access an endpoint with an invalid method.
415Unsupported media type – The file you’ve uploaded is not supported.
500Internal Server Error – We had a problem with our server. Try again later.
503Service Unavailable – We’re temporarially offline for maintanance. Please try again later.
0.0.1

11 months ago

0.0.0

11 months ago