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

skaler

v1.0.7

Published

A 329B client-side image resizer.

Downloads

866

Readme

Skaler is a simple and small tool to scale images client-side. It's ideal when all you want to do is to scale user submitted images before uploading to your server.

Save storage space, bandwidth and reduce server load by scaling images client side before uploading.

~~lack of~~ Features

  • Tiny
  • Vanilla JS
  • Zero Dependencies

Install

$ npm install skaler

This module exposes two module definitions:

  • ES Module: dist/skaler.mjs
  • UMD: dist/skaler.umd.js

Include skaler:

// ES6
import skaler from 'skaler'

// CJS
const skaler = require('skaler');

The script can also be directly included from unpkg.com:

<script src="https://unpkg.com/skaler"></script>

Usage

import skaler from 'skaler';

/**
 * Assume 'input' is the value coming from an input field:
 * <input type="file" accept="image/*" id="input" >
 */

const input = document.getElementById('#input').files[0];

const file = await skaler(input, { scale: 0.5 });
// ~> resized image as a File object - half the size

const file = await skaler(input, { width: 300 });
// ~> resized image as a File object - 300px width

const file = await skaler(input, { width: 300, height: 500 });
// ~> resized image as a File object - stretched to 300x500px

API

skaler(file, options={})

Returns: File <Promise>

Reutnrs promise that resolves to the resized File object.

Note:The new files has an updated last modified time property.

file

Type: File

File object to be resized. This is what input elements of type file returns.

Note: The file is expected to be of type image.

options.scale

Type: number

Scale based on relative percentage. Example:

let file = await skaler(input, { scale: 0.5 });
// ~> output is half the size of the orignal

Note: The width and height options are ignored if scale is provided.

options.width

Type: number

Scale to a specific width. The file keeps it aspect ratio.

let file = await skaler(input, { width: 200 });
// ~> output is 200px width

Note: The image can become stretched if both width and height are provided at the same time.

options.height

Type: number

Scale to a specific height. The file keeps it aspect ratio.

let file = await skaler(input, { width: 200 });
// ~> output is 200px width

Note: The image can become stretched if both width and height are provided at the same time.

options.name

Type: string

Rename file during resizing. Defaults to the name of the input File.

options.type

Type: String

A string representing the MIME type of the content that will be put into the file. Defaults to a value of the input File.

Future

I'd plan to optimize for even better performacne and smaller code using offscreenCanvas and workers in the future as browser support gets better. I also considered createImageBitmap() but it's currently not supported in Safari.

License

MIT © Terkel Gjervig