Skip to content

Instantly share code, notes, and snippets.

@ondrek
Last active December 19, 2015 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ondrek/5872251 to your computer and use it in GitHub Desktop.
Save ondrek/5872251 to your computer and use it in GitHub Desktop.
resize all images
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