---
title: "Experimenting with the IMG Processing SDK"
date: "2024-09-25"
description: "A Node.js tutorial for the IMG Processing SDK: install it with npm, create the client with your API key, upload an image, convert it to PNG and download it."
tags: ["IMG Processing", "Product Design"]
url: "https://rolandoandrade.me/blog/experimenting-with-the-img-processing-sdk/"
author: "Rolando Andrade"
---

# Experimenting with the IMG Processing SDK

> A Node.js tutorial for the IMG Processing SDK: install it with npm, create the client with your API key, upload an image, convert it to PNG and download it.

In the last article, we saw how to get started with the IMG Processing API over HTTP. **[IMG Processing](/projects/img-processing/)** is an API and a Node.js SDK for editing and analyzing images. The HTTP API works, but you still write every request yourself. The SDK removes that work.

[Presenting IMG Processing](https://rolandoandrade.me/blog/presenting-img-processing/): Presenting IMG Processing - In a world of digital media, it is increasingly common to transmit information through images instead of words.

Today, I want to show you how to use the `node-sdk`.

[img-processing-sdk](https://www.npmjs.com/package/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`.

### Install and connect

A Software Development Kit (SDK) is a ready-made library that makes the API easy to use from Node.js projects. You only need your API key. The SDK handles the hard parts for you, like sending HTTP requests, reading responses and parsing data.

Enough talking. Let's see it in action. First, install the SDK.

```bash
npm install img-processing-sdk
```

The library has 3 main classes: `IMGProcessingClient`, `ImageObject` and `IMGProcessingAPIError`. First, let's create the client with our API key:

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

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

Now we have an `IMGProcessingClient` object, the main class of the SDK. It wraps the HTTP requests to the IMG Processing API, so you call simple methods instead. You can see all its methods in the documentation:

[IMGProcessingClient - IMG Processing](https://docs.img-processing.com/sdk/img-processing-client): Simple and easy-to-use way to interact with the IMG Processing API

### Upload and convert

With the client ready, you can call the API with the same methods as the specification. For example, let's upload an image from our file system:

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

After the upload, the method returns an `ImageObject`. It represents an image stored in the IMG Processing API. The object holds information about the image, like its URL, size and format:

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

Besides these read-only properties, the object has many methods. You can review them in the documentation:

[ImageObject - IMG Processing](https://docs.img-processing.com/sdk/image-object): Base class for all image objects

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

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

Now we have the converted PNG image:

```json
{
    "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 is it. We converted the image from JPEG to PNG in one call. Notice the new `id`, the `png` format and the new size, 62504 bytes instead of 27696. If you want to keep the result, download the image and save it to the filesystem:

```typescript
const blob = await pngImage.download();
```

### Help me find bugs

IMG Processing is still a release candidate, a version that is almost final. There may be some random errors. I am still looking for them with a lot of automated testing.

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

[GitHub - img-processing/node-sdk](https://github.com/img-processing/node-sdk): Contribute to img-processing/node-sdk development by creating an account on GitHub.

In the next posts, I will tell you more about these changes. I will also share the wins and the problems I find along the way. 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.

[Book a call with Rolando](https://rolandoandrade.me/pricing/)
