Back to Blog
Experimenting with the IMG Processing SDK

Experimenting with the IMG Processing SDK

September 25, 2024
IMG Processing Product Design

In the last article, we saw how to get started with the IMG Processing API. It is a nice abstract alternative to interact with IMG Processing, a powerful and flexible API and Node.js SDK that provides a wide range of image manipulation and analysis capabilities.

Presenting IMG Processing

Presenting IMG Processing

Presenting IMG Processing - In a world of digital media, it is increasingly common to transmit information through images instead of words.

rolandoandrade.me

Today, I would like to share with you how to use the node-sdk.

img-processing-sdk

img-processing-sdk

img-processing-sdk - SDK for image processing. Latest version: 1.0.0. Start using img-processing-sdk in your project by running `npm i img-processing-sdk`.

www.npmjs.com

Getting Started

A Software Development Kit (SDK) makes the integration of the library into Node.js-based projects easier. This way, with the API key and an intuitive API, you are able to interact with IMG Processing without internal complications like handling HTTP requests and responses, parsing, etc.

Let’s stop talking and see it in action. First, install the SDK.

npm install img-processing-sdk

This library gives us 3 main classes: IMGProcessingClient, ImageObject, and IMGProcessingAPIError. First, let’s initialize the client with our API key:

import { IMGProcessingClient } from 'img-processing-sdk';

const client = new IMGProcessingClient({
    apiKey: process.env.IMG_PROCESSING_API_KEY,
});

This gives us an IMGProcessingClient object, the main class of the IMG Processing SDK. It is a wrapper around http requests to the IMG Processing API, providing a simple and easy-to-use way to interact with the API. You can check the available methods in the documentation:

IMGProcessingClient - IMG Processing

IMGProcessingClient - IMG Processing

Simple and easy-to-use way to interact with the IMG Processing API

docs.img-processing.com

Exploring the SDK

Once you have initialized the client, you can start interacting with the API using the same methods of the specification. For example, let’s upload an image from our file system:

const image = await client.uploadImage({
    image: 'path/to/image.jpg',
    name: 'image.jpg',
});

Once we have uploaded the image, the method returns an ImageObject. It represents an image processed using the IMG Processing API. The object contains information about the image, such as its URL, size, and format, like the following:

{
    "id": "image_b3wfdnk9gjx442a6deayfh17",
    "name": "image.jpg",
    "url": null,
    "width": 700,
    "height": 320,
    "format": "jpeg",
    "size": 27696,
    "created_at": "2024-09-22T16:00:29.700Z"
}

In addition to these read-only properties, the object contains many methods that you can review in the documentation:

ImageObject - IMG Processing

ImageObject - IMG Processing

Base class for all image objects

docs.img-processing.com

For example, let’s convert the image to PNG:

    const pngImage = await image.convert({
      format: "png",
    });

Now we got the converted PNG image:

{
    "id": "image_jwlx4c3p2djgrdrwrja23i74",
    "name": "image.jpg",
    "url": null,
    "width": 700,
    "height": 320,
    "format": "png",
    "size": 62504,
    "created_at": "2024-09-22T16:04:14.078Z"
}

That’s it; we converted the image from JPEG to PNG with no complexities. If you want to store the result, download the image and save it in the filesystem:

const blob = await pngImage.download();

The Next Steps

IMG Processing is still on a release candidate stage, so there could be some random errors that I’m still trying to find through intensive automated testing.

If you find any error, you can create an issue in the GitHub repository:

GitHub - img-processing/node-sdk

GitHub - img-processing/node-sdk

Contribute to img-processing/node-sdk development by creating an account on GitHub.

github.com

During the next posts, I will tell you more about these changes and keep you updated about the achievements and problems I encounter during this new journey. In the meantime, keep experimenting and creating amazing things!


If you enjoy the content, please don’t hesitate to subscribe and leave a comment! I would love to connect with you and hear your thoughts on the topics I cover.

Back to Blog