Created
December 9, 2016 07:46
-
-
Save RaoHai/8821a9222b8d343902e0e7c021d070f0 to your computer and use it in GitHub Desktop.
Simpe Image Resampling
This file contains 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
// var fileInput = document.querySelector('file'); | |
var targetWidth = 400; | |
var targetHeight = 400; | |
function doUpload () { | |
// upload picture | |
} | |
fileInput.onChange = function () { | |
var file = this.files[0]; | |
var reader = new FileReader(); | |
reader.onload = function () { | |
var image = new Image(); | |
image.onload = function () { | |
var canvas = document.createElement('canvas'); | |
var context = canvas.getContext('2d'); | |
context.drawImage(image, 0, 0, targetWidth, targetHeight); | |
var imageData = context.toDataURL('image/png'); | |
doUpload(imageData); | |
} | |
} | |
reader.readAsDataURL(file); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment