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

scaler.pics

v1.1.4

Published

Scaler.pics API helper library for transforming photos and images

Downloads

506

Readme

Scaler.pics

Image resizing and conversion service.

Installation

To use the Scaler Node.js API, install the npm package as follows:

npm install scaler.pics

Basic Usage

Initialize the scaler object with your API key, which you can obtain from Scaler. Then use it to transform images as needed.

import Scaler from 'scaler.pics';

const scaler = new Scaler('YOUR_API_KEY');

const { outputImage } = await scaler.transform({
   input: { localPath: '/path/to/large-image.heic' },
   output: {
      type: 'jpeg',
      fit: { width: 512, height: 512 },
      quality: 0.8,
   },
});

Multiple Outputs

Generate multiple images in a single request (up to 10). Images can be returned as an ArrayBuffer, saved to a specified local path, or uploaded to a storage bucket.

import Scaler from 'scaler.pics';

const scaler = new Scaler('YOUR_API_KEY');

const response = await scaler.transform({
   input: { localPath: '/path/to/large-image.heic' },
   output: [
      {
         type: 'jpeg',
         fit: { width: 1280, height: 1280 },
         quality: 0.8,
         imageDelivery: {
            saveToLocalPath: '/tmp/image-1280.jpeg',
         },
      },
      {
         type: 'jpeg',
         fit: { width: 1024, height: 1024 },
         quality: 0.8,
         imageDelivery: {
            upload: {
               url: signUploadUrl(
                  'https://bucket.domain/path/to/image-1024.jpeg?signature=...'
               ),
               method: 'PUT',
            },
         },
      },
   ],
});

Transform Options

Below are self-explanatory TypeScript interfaces of the transform options.

export interface TransformOptions {
   input: InputOptions;
   output?: OutputOptions | OutputOptions[];
}

interface InputOptions {
   remoteUrl?: string;
   localPath?: string;
   buffer?: Buffer;
}

interface OutputOptions {
   fit: Fit;
   type: OutputImageType;
   quality?: number;
   imageDelivery?: ImageDelivery;
   crop?: NormalizedCrop;
}

interface Fit {
   width: number;
   height: number;
   upscale?: boolean;
}

type OutputImageType = 'jpeg' | 'png' | 'heic';

interface ImageDelivery {
   saveToLocalPath?: string;
   upload?: Upload;
   buffer?: boolean;
}

export interface Upload {
   url: string;
   method?: 'POST' | 'PUT';
}

Exactly one property of the InputOptions object can be specified for the input image. If specifying remoteUrl make sure the URL is valid and the image freely accessible.

You can set either single output or multiple array of outputs (up to 10).

Exactly one optional parameter of ImageDelivery needs to be specified. If imageDelivery itself is undefined, the image will be delivered as an ArrayBuffer.

The upload parameter of ImageDelivery allows you to upload the image directly to services like AWS S3 bucket or Google Cloud Storage. Provide a signed URL and the method for the upload.

Transform Response

export interface TransformResponse {
   inputImage: InputImageInfo;
   outputImage?: OutputImage | OutputImage[];
   timeStats: {
      signMs: number;
      sendImageMs: number;
      transformMs: number;
      getImagesMs: number;
      totalMs: number;
   };
}

interface InputImageInfo {
   pixelSize: Size;
   byteSize: number;
}

interface OutputImage {
   fit: Fit;
   pixelSize: Size;
   image: ImageResult;
}

type ImageResult = ArrayBuffer | string | 'uploaded';

interface Fit {
   width: number;
   height: number;
   upscale?: boolean;
}

interface Size {
   width: number;
   height: number;
}

inputImage contains information about the image sent.

The image property of the OutputImage varies: it can be an ArrayBuffer, a string indicating the image was 'uploaded', or a path to the local file where the transformed image was saved.