meltingice / CamanJS

Javascript HTML5 (Ca)nvas (Man)ipulation
http://camanjs.com
BSD 3-Clause "New" or "Revised" License
3.55k stars 404 forks source link

Use Filters in CamanJs #73

Closed alezala closed 11 years ago

alezala commented 11 years ago

hi!, how to use nostalgia filter ? and other filters with example

meltingice commented 11 years ago

They're just functions like the normal adjustments are.

Caman("#image-id", function () {
  this.nostalgia();
  this.render();
});
Renatico commented 11 years ago

Somebody. Please, help. There is the beautiful example of camanjs operating at camanjs.com/examples but I couldn't repeat it on my local host? I mean how to operate over the several filters' sliders without constantly reloading main picture into the canvas? I need to invoke the method of revent() in order to get source image as a start point after each iteration of using a slider. So the canvas is blinking while the slider is being moved.

meltingice commented 11 years ago

If you call revert() with false, it won't flash back to the original image, but it will reset the internal pixel data. This makes things like sliders work a lot smoother.

Renatico commented 11 years ago

Thank you, Meltingice! Actually, I've tried to do this but it didn't work for me. But now I do exactly the same - put the value of false as an only revert()'s parameter and it works! I'm so funny but I don't understand why it didn't work early.

Renatico commented 11 years ago

Dear, Meltingice! I would be very glad to get yours advice on some issue.

We have the following construction from the Guides:

Caman("#image-id", function () { this.brightness(5).render(); });

We created the object of Caman and when it was completely created we did some operations from the constructor's callback. But let suppose we need for some complex oop-style javascript's object that has one of its field named "this.caman". How can I create the object of Caman against the "image id" and put the object of Caman into the "this.caman"?

I tried: var ImageEffects = function (imgSrc) { var self = this; self.caman = null; self.setNew(imgSrc); }; ImageEffects.prototype.setNew = function(imgSrc) { var self = this; Caman('#mImage', function() // I have the tag of "img" with id="mImage" in my page { self.caman = this; }); };

And I have got an error: constructor ends its work much more faster than Caman's callback and I constantly get console's error message:

Uncaught TypeError: Object [object global] has no method 'process' caman.full.js:21....

while, for example, brightness(5) is being called via the reference to ImageEffects' object:

var ImEf = new ImageEffects('images/1.jpg'); ImEf.caman.brightness(5).render();

Have you got some ideas? Thanks in advance.

meltingice commented 11 years ago

You have a race condition. The reason that you provide a callback to the Caman() function is because initialization of CamanJS is asynchronous. Thus, when you do:

var ImEf = new ImageEffects('images/1.jpg');
ImEf.caman.brightness(5).render();

CamanJS is not fully initialized yet and you try to render to an incomplete canvas. You will need to wait for initialization one way or another. Either with a callback or some other means.

Renatico commented 11 years ago

Thank you for your response! I will dig it more.

Renatico commented 11 years ago

Dear, Meltingice. I made filters' grid like we have into the examples' page at camanjs.com/examples/. And it's OK. But when I set the value of 'sharpen' to other value than zero, I constantly get an error in Chrome's Developer Tools Console:

Uncaught TypeError: Object # has no method 'processFn' caman.full.js:1987 Caman.Renderer.Renderer.renderBlock caman.full.js:1987 (anonymous function)

But if other filters except 'sharpen' set to zeroes then I haven't got such error. I can move 'sharpen's slider from the left to the right and vice versa and there are not any errors in the console. This error takes place only when there is at least one other filter has its value that is more than zero.

Have you got any ideas? Thank you as always in advance.