CamanJS icon indicating copy to clipboard operation
CamanJS copied to clipboard

Saving callback

Open DustinHigginbotham opened this issue 12 years ago • 7 comments

Perhaps I am missing something, but is there a way we can have an onSave style callback? I'm in a node.js environment and this could be very useful for me.

Thanks!

DustinHigginbotham avatar Jul 29 '13 03:07 DustinHigginbotham

You're right, there isn't. Marking this as a to-do item.

meltingice avatar Jul 29 '13 17:07 meltingice

If I were to implement this myself, should it be registered as an Event or should another parameter be passed into the save function?

I think what makes it interesting is the node and browser support. Would it make sense to have a save callback if you are in the browser?

DustinHigginbotham avatar Jul 29 '13 18:07 DustinHigginbotham

It would not make sense to have a callback for the browser version because the way save works is by redirecting the browser to the base64 encoded URL.

That said, the way the save() function works is by delegating to either browserSave or nodeSave depending on the environment. Because of this, I would allow both an optional callback to nodeSave and fire an imageSaved event.

meltingice avatar Jul 29 '13 18:07 meltingice

I was working on this feature. I have a callback firing if defined on the save method. Then I added the event type to make use of the whole event system when I realized if I target a single instance like so:

Caman.Event.listen(c, 'imageSaved', function() { /* ... */ });

...Nothing fires. If I run this without the target instance, it works fine. Looking into this more, it looks as if the id set during initialization is null/undefined in the event system (console.log(target.id)). I'm wondering if I am missing something or if you have any insight on what could be happening here. I'm more than willing to fix this, but some guidance would be awesome. :)

DustinHigginbotham avatar Jul 31 '13 16:07 DustinHigginbotham

Is there any way to check for a callback once the image is loaded so I can call the caman functions once the caman object is ready?

ie var tempCanvas = document.createElement('canvas'); var c = Caman(tempCanvas, 'path/to/image.jpg'); if (c.isLoaded) { c.reset(); c.resize({width: new_w, height: new_h}); c.render(); }

I need the callback to be external because the crop and resize functions I want to apply are using variables outside the scope of an anonymous function callback.

jeffreyqua avatar Mar 19 '14 22:03 jeffreyqua

There isn't right now, but I could see that being a nice little addition. I'll make a separate issue for it.

meltingice avatar Mar 20 '14 13:03 meltingice

So, no way to know when the file has actually been saved when working with CamanJS in node?

edit: just read the code and will probably use this.canvas.toBuffer() directly

raine avatar Aug 23 '14 16:08 raine