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

browser-image-manipulation

v0.4.0

Published

Convert and manipulate image on JS in browser.

Downloads

2,907

Readme

browser-image-manipulation

Convert and manipulate image on JS in browser. Fluent interface based, at end returning promise.

Install

npm install browser-image-manipulation --save

Examples

Open (see in /examples)

Features

Load image in formats:

  • blob (optional, with image orientation detect and correct rotate)
  • canvas

Filters:

Manipulations:

  • rotate
  • crop
  • crop to circle with resize
  • crop to square with resize
  • resize by max height/max width (used pica for correct resize image)
  • resize to fit in rectangle (proportion saved, empty space filled by color)
  • perspective (change perspective of image)

Draw:

  • draw line
  • draw polygon
  • draw rectangle
  • draw text

Output formats:

  • blob
  • canvas
  • base64 image

Info:

  • get exif (only for blob)

Usage

One format:

import BrowserImageManipulation from 'browser-image-manipulation'

new BrowserImageManipulation()
   .loadBlob(e.target.files[0], {
       fixOrientation: true // about problem: https://www.howtogeek.com/254830/why-your-photos-dont-always-appear-correctly-rotated/
   })
   .gaussianBlur()
   .saveAsImage()
   .then(base64 => {
      alert('Blured done!')
   })
   .catch(e => alert(e.toString()))

Multi format:

import BrowserImageManipulation from 'browser-image-manipulation'

let picaOptions = {} // optional, see pica options
let iM = new BrowserImageManipulation()
            .loadBlob(e.target.files[0])
            .toCircle(300, {pica: picaOptions})
            .toGrayscale()
            
iM.saveAsBlob().then(blob => {
    if (blob.size > 3000000) {
        return new Error('Max size 3 mb')
    }
    // uploadToServer(blob, 'my circle black and white image')
    return iM.saveAsImage()
}).then(base64 => {
    document.getElementByTag('img')[0].src = base64
}).catch(e => alert(e.toString()))

Fluent interface:

new BrowserImageManipulation()
    .loadBlob(e.target.files[0])
    .toCircle(400)
    .toGrayscale()
    .pixelize()
    .rotate(90)
    .saveAsImage()
    .then(base64 => {
        document.getElementById('exampleFluentImg').src = base64
    }).catch(e => alert(e.toString()))

Increase performance

Minify

Use wasm features in resize methods:

new BrowserImageManipulation()
    .loadBlob(e.target.files[0])
    .toCircle(400, {
        picaInit: {
            features: ['js', 'wasm'] // <--- set features
        }
    })
    
new BrowserImageManipulation()
    .loadBlob(e.target.files[0])
    .resize(400, 400, {
        picaInit: {
            features: ['js', 'wasm'] // <--- set features
        }
    }) 
   
// ...and etc resize methods    

But if use UglifyJs/TerserJS set in compress evaluate to false

compress: {
  ...
  evaluate: false
  ...
}

Without that, you can see error like:

Uncaught ReferenceError: e is not defined
    at t (217c2170-1eb8-41b8-b91c-c3d57f706ea9:1)

Ie 11 support

For work in ie 11 you need some polyfils from core-js

import 'core-js/modules/es.object.assign'
import 'core-js/modules/es.promise'
import 'core-js/modules/es.array.iterator'

In the versions below, the work was not tested. Perhaps everything will work if you add polyfills and use only js features:

.resize(400, 400, {
        picaInit: {
            features: ['js'] // <--- only js feature
        }
    }) 

Development

# install deps
npm i

# run in dev mode
npm run dev

and go to /examples/index.html and open in web-browser