Open DustinHigginbotham opened 11 years ago
You're right, there isn't. Marking this as a to-do item.
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?
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.
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. :)
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.
There isn't right now, but I could see that being a nice little addition. I'll make a separate issue for it.
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
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!