Created
January 25, 2014 07:28
-
-
Save jarek-foksa/8613003 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let extractBitmapSize = (bitmap, callback) => { | |
| let imageElement = new Image(); | |
| imageElement.onload = () => { | |
| callback(imageElement.naturalWidth, imageElement.naturalHeight); | |
| }; | |
| imageElement.src = bitmap; | |
| }; | |
| document.body.addEventListener('drop', (event) => { | |
| event.stopPropagation(); | |
| event.preventDefault(); | |
| let files = event.dataTransfer.files; | |
| for (let file of files) { | |
| if (file.type === 'image/png') { | |
| let reader = new FileReader(); | |
| reader.readAsDataURL(file); | |
| reader.addEventListener('load', (event) => { | |
| let bitmap = event.target.result; | |
| extractBitmapSize(bitmap, (width, height) => { | |
| let image = SVG`<image></image>`; | |
| image.setAttribute('width', width); | |
| image.setAttribute('height', height); | |
| image.setAttributeNS(xlinkNS, 'xlink:href', `${bitmap}`); | |
| image.appendTo(this.graphics); | |
| }); | |
| }); | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment