1.0.0 • Published 4 months ago

pixellab-node v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

pixellab-node

A simple client for interacting with the Pixel Lab Developer API.

In order to process image data you can use the Node API (see example below) or a library like JIMP or sharp

Installation

  • npm i NOTE: project requries Node 18+
  • Create a .env file with your Pixellab API key (see .env.example)
  • Import and initialize the client

Simple NextJS Example

import PixelLabClient, {
  AnimateSkeletonResponse,
  Base64Image,
  SkeletonKeypoints,
} from "pixellab-node";
import Image from "next/image";
import fs from "fs/promises";
import path from "path";
import corgiJsonData from "../../public/skeleton_keypoints.json";

async function getImageAsBase64(imageName: string): Promise<string> {
  try {
    const imagePath = path.join(process.cwd(), "public", imageName);
    const imageBuffer = await fs.readFile(imagePath);
    const base64Image = imageBuffer.toString("base64");
    return base64Image;
  } catch (e) {
    console.error(e);
    throw e;
  }
}

export default async function Home() {
  const client = new PixelLabClient();
  const startingImage = await getImageAsBase64("corgi-test-dog.png");
  const skeletonResult: AnimateSkeletonResponse =
    await client.animateSkeletonFromSkeleton({
      skeleton_keypoints: corgiJsonData.pose_keypoints as SkeletonKeypoints,
      image_size: { width: 64, height: 64 },
      reference_image: { type: "base64", base64: startingImage },
    });

  return (
    <main className="flex flex-row items-center bg-slate-700 text-white">
      {skeletonResult.images.map((image: Base64Image, index: number) => {
        return (
          <Image
            alt={`Corgi Test Animation (${index})`}
            key={index}
            src={`data:image/png;base64,${image.base64}`}
            width={64}
            height={64}
          />
        );
      })}
    </main>
  );
}

corgo-test

Note: the above example uses skeleton keypoint data exported from Aesprite

Authentication

You must use your Pixellab API key in order to authenticate. Logged in users can find that here Remember: never share your API key with anyone

1.0.0

4 months ago

0.7.1

4 months ago

0.7.0

4 months ago

0.6.0

5 months ago

0.5.2

5 months ago

0.5.1

5 months ago

0.4.0

5 months ago

0.3.1

5 months ago

0.3.0

5 months ago

0.2.0

5 months ago

0.1.0

5 months ago