Last active
December 19, 2015 00:59
-
-
Save ondrek/5872251 to your computer and use it in GitHub Desktop.
resize all images
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
function resize(originalImage) { | |
var img = new Image(); | |
img.src = originalImage.attr('src'); | |
img.id = originalImage.attr('id'); | |
img.onload = function(){ | |
console.log(img); | |
var canvas = document.createElement("canvas"); | |
canvas.width = 100; | |
canvas.height = 100; | |
var ctx = canvas.getContext("2d"); | |
ctx.drawImage(img, 0, 0, 100, 100); | |
$(img.id).attr('src', canvas.toDataURL("image/jpeg")); | |
}; | |
} | |
$('img').each(function() { | |
var originalImage = $(this); | |
resize(originalImage); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment