npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

photoroom-sdk

v1.0.1

Published

A simple but effective wrapper for the Photoroom API

Downloads

35

Readme

Photoroom API wrapper for Node.js

NPM version Downloads Twitter Follow

The Photoroom API is quite easy to use, but it can always be easier with this package.

Requirements

Get your API key from the Photoroom website.

Installation

npm i photoroom-sdk

API

import Photoroom from "photoroom-sdk";

const photoroom = new Photoroom("INSERT PHOTOROOM API KEY");

photoroom.removeBgFromImage({...})

The parameters you can pass to the removeBgFromImage function are::

Only the image_file_b64 property is mandatory.

| Property | Type | Description | | -------------- | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | image_file_b64 | "string" | The image you want to remove the background from, in base 64 format. | | format | "png", "jpg" | Format of the returned image. Can be "png" (default) or "jpg" (faster, no transparency). | | channels | "rgba", "alpha" | If "rgba" (default), a composed image is returned. If "alpha", a black and white image is returned, where white is the foreground and black is the background. | | bg_color | "string" | Can be a "hex code" ("#FF00FF") or a "HTML" color (red, green, etc...). If provided, sets the background of the returned image to the specified color. | | size | "preview", "medium", "hd", "full" | Will resize the output to the specified size. Can be "preview" (0.25 Megapixels), "medium" (1.5 MP), "hd" (4 MP) or "full" (36 MP, can be slower for large images). Useful for mobile apps that need smaller images. Setting preview uses 0.25 credit. | | crop | "boolean" | If "true", the image returned is cropped to the cutout border. Transparent pixels are removed from the border. |

And the output properties are:

| Property | Type | Description | | ---------- | -------- | ---------------------------------------------------- | | result_b64 | string | Base64 encoded representation of the returned image. |

How to use removeBgFromImage

Remove the background from a local file.

import Photoroom from "photoroom-sdk";
import fs from "fs";

const photoroom = new Photoroom("INSERT PHOTOROOM API KEY");

// convert your image file to base 64 format
const convertImgFileToBase64 = fs.readFileSync(
  `${__dirname}/image.jpg`,
  "base64"
);

// pass it through photoroom.removeBgFromImage
photoroom
  .removeBgFromImage({
    image_file_b64: convertImgFileToBase64,
    bg_color: "blue",
  })
  .then((res) => {
    // do whatever you want with the base64 image response
    // like saving into a file
    fs.writeFileSync(
      `${__dirname}/img-bg-removed.jpg`,
      res.result_b64.replace(/^data:image\/\w+;base64,/, ""),
      { encoding: "base64" }
    );
  });

Or have a cool async/await example:

import Photoroom from "photoroom-sdk";
import fs from "fs";

const photoroom = new Photoroom("INSERT PHOTOROOM API KEY");

// convert your image file to base 64 format
const convertImgFileToBase64 = fs.readFileSync(
  `${__dirname}/image.jpg`,
  "base64"
);

// pass it through photoroom.removeBgFromImage
const response = await photoroom.removeBgFromImage({
  image_file_b64: convertImgFileToBase64,
  bg_color: "blue",
});

// do whatever you want with the base64 image response
// like saving into a file
fs.writeFileSync(
  `${__dirname}/img-bg-removed.jpg`,
  response.result_b64.replace(/^data:image\/\w+;base64,/, ""),
  { encoding: "base64" }
);