Code Monkey home page Code Monkey logo

pica's Introduction

pica - high quality image resize in browser

Build Status NPM version

pica is one more experiment with high speed javascript, from authors of paco. It does high quality images resize in browser as fast as possible.

demo

If you need to resize image in modern browser, you will note, that canvas uses low quality interpolation algorythms. That's why we did pica.

  • It's not as fast as canvas, but still reasonable fast. With Lanczos filter and window=3, and huge image 5000x3000px resize takes ~1s on desktop and ~3s on mobile.
  • If you browser supports Webworkers, pica automatically use it to avoid interface freeze.

Why it's useful:

  • reduce upload size for big images - save time and traffic
  • save server resources for image processing

Install

node.js (to develop, build via browserify and so on):

npm install pica

bower:

bower install pica

API

.resizeBuffer(options, callback)

Async resize Uint8Array with RGBA image.

  • options:
    • src - Uint8Array with source data.
    • width - src image width.
    • height - src image height.
    • toWidth - output width.
    • toHeigh - output height.
    • quality - 0..3. Default - 3 (lanczos, win=3).
    • alpha - use alpha channel. Default - false.
    • __unsharpAmount - 0..500. Default - 0 (off). Usually 50..100 is good.
    • unsharpThreshold - 0..100. Default - 0. Try 10 for begibing.
    • dest - Optional. Output buffer to write data. Help to avoid data copy if no WebWorkers available. Callback will return result buffer anyway.
    • transferable - Optional. Whether to use transferable objects. Faster, but you cannot use the source buffer afterward.
  • callback(err, output) - function to call after resize complete:
    • err - error if happened.
    • output - Uint8Array with resized RGBA image data.

.resizeCanvas(options, callback)

Resize image from one canvas to another. Sizes are taken from canvas.

  • from - source canvas.
  • to - destination canvas.
  • options - quality (number) or object:
    • quality - 0..3. Default - 3 (lanczos, win=3).
    • alpha - use alpha channel. Default - false.
    • __unsharpAmount - 0..500. Default - 0 (off). Usually 50..100 is good.
    • unsharpThreshold - 0..100. Default - 0. Try 10 for begining.
  • callback(err) - function to call after resize complete:
    • err - error if happened

.WW - true/false

true if webworkers supported. You can use it for capabilities detection. Also, you can set it false for debug, and pica will use direct function calls.

What is quality

Pica has presets, to vary speed/quality ratio. To simplify interface, you can select this presets with quality option param:

  • 0 - Box filter, window 0.5px
  • 1 - Hamming filter, window 1.0px
  • 2 - Lanczos filter, window 2.0px
  • 3 - Lanczos filter, window 3.0px

Unsharp mask

Pica has built in unsharp mask, similar to photoshop, but limited with radius 1.0. It's off by default. Set unsharpAmount and unsharpThresold to activate filter.

References

You can find this links useful:

Authors

Licence

MIT

pica's People

Contributors

devongovett avatar llacroix avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.