Activate your free membership today | Log-in

Thursday, December 18th, 2008

Pixastic: JavaScript Image Manipulation Library

Category: Canvas, JavaScript

Pixastic uses <canvas>'s ability to expose raw pixel information to perform Photoshop-style image manipulation effects all in your standards-based browser. For an example of Pixastic in action, the library's authors have built a cute little Photoshop clone in a browser:

Here's an example of using the underlying API:

JAVASCRIPT:
  1.  
  2. var img = document.getElement("myImage"); // get the image element
  3.  
  4. if (img.complete) {     // make sure the image is fully loaded
  5.         Pixastic.process(
  6.                 img,
  7.                 "brightness",   // brightness/contrast adjustment
  8.  
  9.                 {              // options object
  10.  
  11.                         "brightness" : 60,      // set brightness option value to 60
  12.                         "contrast" : 0.5,       // set contrast option value to 0.5,
  13.                         "rect" : {            // apply the effect to this region only
  14.                                 "left" : 100,
  15.                                 "right" : 100,
  16.                                 "width" : 200,
  17.                                 "height" : 150
  18.                         }
  19.                 }
  20.         )
  21. }
  22.  

There's also a jQuery plug-in wrapper, allowing you to do stuff like this:

JAVASCRIPT:
  1.  
  2. // invert the image with id="prettyface"
  3. $("#prettyface").pixastic("invert");
  4.  
  5. // convert all images with class="photo" to greyscale
  6. $(".photo").pixastic("desaturate");
  7.  
  8. // chained blur and a regional emboss, see image further down
  9. $("#myimage")
  10.         .pixastic("blurfast", {amount:0.2})
  11.         .pixastic("emboss", {direction:"topleft", rect:{left:50,top:50,width:150,height:150}});
  12.  

The architecture of the library is nice; there's a small core Pixastic library file (pixastic.core.js) and then each effect is factored out into its own JS file. A handy web interface lets you download your own minified subset of Pixastic.

Cool!

Posted by Ben Galbraith at 11:57 am

++++-
4 rating from 24 votes

9 Comments »

Comments feed TrackBack URI

Very cool to see something like this done in native browser code. Wish it had an undo button though.

Comment by tj111 — December 18, 2008

Tip: Ctrl+Z

Comment by jseidelin — December 18, 2008

That’s really awesome. What license will the code have? It just needs a way to save it up to a server and it’s a great tool for a CMS.

Comment by Fyzbo — December 18, 2008

The library is available under the MIT license, the editor code is closed for now.
Also, blog post: http://blog.nihilogic.dk/2008/12/pixastic-now-javascript-image.html

Comment by jseidelin — December 18, 2008

Very Nice! just another one of the many cool uses of Ajax!

Comment by cssProdigy — December 18, 2008

Here is an example of image resizing [seam-carving] using the canvas tag

http://n.parashuram.googlepages.com/seamcarving.html
Details here -
http://dy-verse.blogspot.com/search/label/seam%20carving

Comment by axemclion — December 18, 2008

Great respectable work! Online apps are definitely the way forth, and seeing a good system for graphic manipulation is another step forward!

Comment by oopstudios — December 19, 2008

But what do you do with the image after you’ve altered it? Is there a server-side component as well so that you can actually write the changes to disk? If not, this is just a toy, no matter how slick.

Comment by starkraving — December 19, 2008

@starkraving uhh if it’s canvas you can just right click, save as. You get a png. This is true for any canvas based app.

Comment by Breton — December 19, 2008

Leave a comment

You must be logged in to post a comment.