MattKetmo / darkroomjs

Extensible image editing tool in your browser
https://mattketmo.github.io/darkroomjs
MIT License
1.41k stars 406 forks source link

Where can you acces the image? #93

Open Nummer987 opened 8 years ago

Nummer987 commented 8 years ago

Thats the last part of the githug discription. It says you ahve to edit this code: save: { callback: function() { this.darkroom.selfDestroy(); // Cleanup var newImage = dkrm.canvas.toDataURL(); fileStorageLocation = newImage; } } but where do you have to implement it? Need help :/

melefabrizio commented 8 years ago

You need to pass that save object in the new Darkroom call:

function yourFunction(base64Blob){
  //Here you do whatever you want with the base64 string
}
new Darkroom('#target', {
  ...
  // Plugins options
  plugins: {
    crop: {
      minHeight: 50,
      minWidth: 50,
      ratio: 1
    },
    save: {
      callback: function() {
        this.darkroom.selfDestroy(); // Cleanup
        var newImage = dkrm.sourceCanvas.toDataURL();
        yourFunction(newImage) 
      }
  }
  },
});

yourFunction receives newImage, that is a base64 string, then you can set it as src of an <img> tag or post it via AJAX to a php script to save it to file.