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

blitz-resize

v0.4.0

Published

Most versatile, powerful, and fastest way to resize an image. Fast, non-blocking (does not freeze windows), and async/await/promise compatible.

Downloads

354

Readme

This is a complete re-write of viliusle's hermite resize.

Black with Thunder Icon Basketball Logo-2

Blitz is the most versatile, powerful, and fastest way to resize an image. It is fast, non-blocking (does not freeze windows), and async/await/promise compatible.

Blitz resizes high resolution DSLR images in a matter of seconds. Precipitously cut upload time by resizing your image on the client-side, yet achieve high quality and performace using Hermite filter.

Blitz

Installation

npm install blitz-resize --save

Usage

const blitz = Blitz.create()

/* Promise */
blitz({
    source: DOM Image/DOM Canvas/jQuery/DataURL/File,
    width: 400,
    height: 600
}).then(output => {
    // handle output
}).catch(error => {
    // handle error
})

/* Await */
let resized = await blizt({...})

/* Old school callback */
const blitz = Blitz.create('callback')
blitz({...}, function(output) {
    // run your callback.
})

Why use Blitz

Precipitously cut image upload time and server loads by doing client-side image resizing. Blitz is non-blocking so you will not experience UI freeze when it is resizing. Advanced scaling options with max or min height/width.

Full options

blitz({
    source: DOM Image/DOM Canvas/jQuery/DataURL/Javscript #File,
    
    // when only 1 is defined, the other will be scaled proportionally by default.
    width: (number), // optional
    height: (number), // optional

    // if width/height is defined, all max and mins are ignored
    maxWidth: (number),
    maxHeight: (number),
    minWidth: (number),
    minHeight: (number),

    proportional: true (default)/false, // if set to false, resizing will not attempt to maintain proportions

    // [optional] jpg, gif, png or raw. when not defined, assumes png.
    outputFormat: 'jpg',

    // [optional] `image`, `canvas`, `data`, `download`, `blob`, or `flie` for Javascript #File.
    // If not entered output is same as input format.
    output: 'data',  

    // [optional] applicable for `image`, `file` or `data` output only
    quality: 0.7, // between 0 to 1.

    // [optional] if you want to know how fast blitz resize       
    logPerformance: true/false
}).then(output => {
    // outputs:

    // 'image' -- Image <Object: Image>: This will be the Image DOM, which you can append to your DOM.
    // 'canvas' -- HTML Canvas
    // 'data' -- DataURL <String>: You can attach it to <img src> or just redirect to it to show on browser.
    // 'download' -- <Function>: You need to call this function to run the download.
    // 'blob' -- Blob <Function>: Javascript Blob object
    // 'file' -- File <Object>: Javascript File object


}).catch(err => {
    // handle err
})

Examples

<input type="file" capture="camera" accept="image/*" id="cameraInput" name="cameraInput">
<script>
function readFile(file) {
    var reader = new FileReader();
    reader.onload = readSuccess;

    function readSuccess(evt) {

        // data to data (async/await style)
        var bAwait = Blitz.create()
        try {
            let output = await bAwait({
                source: evt.target.result,

                // image will be resized to strictly 400x600
                // `proportional: true` will be ignored as it cannot be enforced.
                width: 400,
                height: 600,

                outputFormat: 'jpg',
                output: 'data',
                quality: 0.7,
                logPerformance: true,

                proportional: true // this is ignored.
            })
            console.log('Resize using event successful')
            // data is a string you can attach to image src.
            var image = new Image()
            image.src = data
            document.getElementByTag('body').append(image)
        } catch(err) {
            console.log(err)
        }

        // image -> canvas (promise-style)
        var img = new Image()
        img.src = evt.target.result
        
        // using #Object.create and then the #resize method is similar to Blitz.create('callback')
        var bPromise = Blitz.create()
        img.onload = function() {
            bPromise.resize({
                source: img,

                // image will be resized to width 400, and height will be scalled proportionally (by default)
                width: 400,

                outputFormat: 'jpg',
                output: 'canvas',
                quality: 0.7,
                logPerformance: true
            }).then(canvas => {
                console.log('Resize using img to canvas successful')
                document.getElementByTag('body').append(canvas)
            })
        }

        // data -> image (callback-style)
        var bCallback = Object.create(Blitz)
        bCallback.resize({
            source: evt.target.result,

            // image will be scaled to maxWidth of 640, with minHeight of 400
            // if it cannot be constrained, it will break proportionality.
            maxWidth: 640,
            minHeight: 400,

            outputFormat: 'jpg',
            output: 'image',
            quality: 0.7,
            logPerformance: true
        }, function(image) {
            console.log('Resize using data successful')
            // output is just a standard image DOM.
            // you can append it to your DOM.
            document.getElementByTag('body').append(image)
        })

    };
    reader.readAsDataURL(file);
}

document.getElementById('cameraInput').onchange = function(e) {

    // file -> file
    var b5 = Blitz.create()

    b5({
        source: e.srcElement.files[0],

        // image will be up or downscaled to always have minHeight of 600
        minHeight: 600,

        outputFormat: 'jpg',
        quality: 0.7,        
        logPerformance: true
    }).then(download => {
        console.log('Resize using file successful')
        // output is a download function.

        // run some operations

        // then call #download to download the file.
        download()

    }).catch(err => {
        console.log(err)
    })

    readFile(e.srcElement.files[0]);
};
</script>

License

Blitz is MIT licensed.