News for hackers. Stuff that matters.
Re:Grafi.js – JavaScript Image Processing Library by onion2k on Tuesday April 26, 2016 @03:19AM (#11570001)
You can do many of these effects in plain CSS using the filter operator. As a bonus, you get hardware acceleration if you combine them with translate3d(0, 0, 0).
Re:Grafi.js – JavaScript Image Processing Library by feiss on Tuesday April 26, 2016 @03:24AM (#11570023)
That's cool, but that doesn't interfere with the library main goal:

"grafi.js is a library intended for learning about how image processing works"

Re:Grafi.js – JavaScript Image Processing Library by benjaminbenben on Tuesday April 26, 2016 @05:41AM (#11570515)
I saw Mariko give a talk about this last week - http://2016.render-conf.com/talks#drawing-on-canvas-a-few-th...

It was absolutely fantastic; really great information about image data & how to process it.

Re:Grafi.js – JavaScript Image Processing Library by dkopi on Tuesday April 26, 2016 @03:44AM (#11570098)
Also - CSS tricks don't work if you're writing command line tools or backend code in JS.
Re:Grafi.js – JavaScript Image Processing Library by onion2k on Tuesday April 26, 2016 @03:55AM (#11570136)
That is true, but grafi.js relies on a browser's canvas API to convert an image to a Uint8ClampedArray of colour values, so it won't work on a command line or backend either. As a way to learn about convolution filters it seems fairly good though.
Re:Grafi.js – JavaScript Image Processing Library by dkopi on Tuesday April 26, 2016 @04:08AM (#11570180)
Good point. https://www.npmjs.com/package/get-pixels can help parse an image to pixels, but it returns a different format than the canvas API's Uint8ClampedArray.
Re:Grafi.js – JavaScript Image Processing Library by megalodon on Tuesday April 26, 2016 @08:53AM (#11571380)
I haven't tested but I think you can convert ndarray to Uint8ClampedArray by doing

    new Uint8ClampedArray(ndarray.data);
Re:Grafi.js – JavaScript Image Processing Library by zbjornson on Tuesday April 26, 2016 @11:07AM (#11572480)
Node-canvas provides a compliant Canvas implementation:

https://github.com/Automattic/node-canvas

Re:Grafi.js – JavaScript Image Processing Library by alfanick on Tuesday April 26, 2016 @01:15PM (#11573733)
that is wrong way to do this - write efficient code (simple operations on an array) instead of using huge canvas library to make a library you don't need to use usable
Re:Grafi.js – JavaScript Image Processing Library by kowdermeister on Tuesday April 26, 2016 @01:22PM (#11573784)
And she beats the purpose instantly by adding this to the readme:

    they code is pretty rough & documentation is not great
There are much better tutorials out there for image processing: http://www.html5rocks.com/en/tutorials/canvas/imagefilters/
Re:Grafi.js – JavaScript Image Processing Library by rayshan on Tuesday April 26, 2016 @02:50PM (#11574525)
The better way of triggering hardware acceleration nowadays is with the CSS will-change API: https://developer.mozilla.org/en-US/docs/Web/CSS/will-change
Re:Grafi.js – JavaScript Image Processing Library by globuous on Tuesday April 26, 2016 @04:56AM (#11570337)
What I thought was really cool about this though, is that I can start making a "mini-photoshop". It wouldn't be very efficient at all, but I think you could find a way to mix effects together on parts of the picture selected by the user which is what a mini-photoshop is to me. Or maybe I should just look into canvas, but at least I have the choice now.

And even if I programmatically insert inline CSS, there's always the compatibility issues and filter restrictions.

Re:Grafi.js – JavaScript Image Processing Library by rawnlq on Tuesday April 26, 2016 @05:16AM (#11570411)
Photo editing using webgl already existed for a couple years now:

http://evanw.github.io/webgl-filter/

http://photogl.net/

https://v3.polarr.co/ (this one seems to be the only real company instead of a demo)

Re:Grafi.js – JavaScript Image Processing Library by _jomo on Tuesday April 26, 2016 @03:55AM (#11570135)
For node.js I really like lwip [0], there don't seem to be many image processing libraries around but this one covers the most common manipulations and it's written in C++ so it's quite fast.

0: https://github.com/EyalAr/lwip

Re:Grafi.js – JavaScript Image Processing Library by Kequc on Tuesday April 26, 2016 @12:01PM (#11572987)
This looks excellent.

I'm well versed in imagemagick to such a degree that I stopped taking on projects that would have to use it. Which is a large subset of projects. Now that I'm primarily Node and Javascript focused I'll bring this up next time.

Re:Grafi.js – JavaScript Image Processing Library by dawnerd on Tuesday April 26, 2016 @12:17PM (#11573131)
Does it work with node 4+ now? I was using it on node 0.12 and it worked like a champ.
Re:Grafi.js – JavaScript Image Processing Library by _jomo on Wednesday April 27, 2016 @08:50AM (#11579874)
Using it with node 4.4, no issues to report.
Re:Grafi.js – JavaScript Image Processing Library by phoboslab on Tuesday April 26, 2016 @04:22AM (#11570231)
A while ago I wrote a similar library, running on the GPU using WebGL[1].

It's interesting how the library just became a _wrapper_ around 3 very simple pixel shaders (color matrix, convolution and blur), with the GPU doing all the looping over each pixel for you. Imho the shaders explain the idea of each filter much more clearly than iterative code could.

[1] http://phoboslab.org/log/2013/11/fast-image-filters-with-web...

Re:Grafi.js – JavaScript Image Processing Library by rasz_pl on Tuesday April 26, 2016 @04:44AM (#11570299)
on a browser with canvas support:

Uncaught exception: DOMException: NOT_SUPPORTED_ERR Error thrown at line 58, column 6 in formatter(pixelData, width, height) in http://grafijs.org/grafi.js: return new window.ImageData(pixelData, width, height) called from line 471, column 4 in invert(imgData) in http://grafijs.org/grafi.js: return formatter(newPixeldata, imgData.width, imgData.height) called from line 147, column 4 in <anonymous function: $img.onload>() in http://grafijs.org/: imageCtx.putImageData(grafi.invert(original), 0, 0)

Re:Grafi.js – JavaScript Image Processing Library by greenpizza13 on Tuesday April 26, 2016 @04:37PM (#11575425)
I have to imagine this will be entirely too slow to do any heavy lifting. Low level matrix support is really important otherwise your convolution is big fat nested loops.
Re:Grafi.js – JavaScript Image Processing Library by Kiro on Tuesday April 26, 2016 @04:39AM (#11570283)
What's the point of using Uint8ClampedArray instead of just a normal array?
Re:Grafi.js – JavaScript Image Processing Library by zschuessler on Tuesday April 26, 2016 @10:12AM (#11571997)
More than speed, it's easier working with the Uint8ClampedArray since the values correlate to RGB values (0-255). If it was a matter of speed only, the author would have used Uint32Array, which gets the speed benefit of typed arrays but allows for larger values (meaning smaller overall array size, but it's more complex to work with).

If you hop down to the annotated source, you can see Uint32Array used here:

http://zschuessler.github.io/DeltaE/demos/de76-chroma-key/

Re:Grafi.js – JavaScript Image Processing Library by onion2k on Tuesday April 26, 2016 @06:23AM (#11570671)
Re:Grafi.js – JavaScript Image Processing Library by imaginenore on Tuesday April 26, 2016 @07:19AM (#11570874)
asm.js