desuwa / tegaki

Oekaki-style painter app in JavaScript
MIT License
95 stars 12 forks source link

redraw image #6

Closed usf closed 4 years ago

usf commented 8 years ago

Hi! Thanks for awesome plugin! How can i redraw image, that was saved and sent to the server? For example i have some oekaki.png and want to use it for default background for my new Tegaki.open()

desuwa commented 8 years ago

There's no easy way to open images directly right now. I'll fix this eventually.

For now you can either draw your picture on the background canvas manually: https://github.com/desuwa/tegaki/blob/master/tegaki.js#L1591-L1606

or hijack the built-in background switcher:

Tegaki.open({
  onDone: function() { window.open(Tegaki.flatten().toDataURL('image/png')); },
  onCancel: function() { console.log('Closing...')},
  width: 500,
  height: 500,
  canvasOptions: function() {} // you need this
});

var img = T$.el('img');
img.onload = Tegaki.onImageLoaded;
img.onerror = Tegaki.onImageError;
img.src = 'http://example.com/image.png'; // image URL

Demo for the background selector: https://bbs.neet.tv/vip/read/22 (you have a drop-down select menu with editable images below the canvas). The canvasOptions function passed to Tegaki.open is what generates the drop-down menu entries: https://github.com/desuwa/hivebbs/blob/master/public/js/hive.js#L298-L319

usf commented 8 years ago

Work like a charm, ty a lot!