Skip to content

Instantly share code, notes, and snippets.

@haruair
Forked from simonkim/sshow_load_img
Created July 30, 2013 03:43
Show Gist options
  • Save haruair/6110045 to your computer and use it in GitHub Desktop.
Save haruair/6110045 to your computer and use it in GitHub Desktop.
function sshow_load_img1(src, loaded) {
/* NOT possible to document.createElement('canvas').getContext('2D').drawImage( img or img.get() ) */
var img = $("<img />").attr('src', src )
.load(function() {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
alert('broken image!');
} else {
if (loaded) loaded(img);
}
});
}
function sshow_load_img2(src, loaded) {
/* Possible to document.createElement('canvas').getContext('2D').drawImage( img ) */
var img = new Image();
img.onload = function() {
if ( loaded ) loaded (img);
};
img.src = src;
}
function sshow_load_img3(src, loaded) {
var img = $("<img />").attr('src', src)
.load(function() {
var img = new Image();
img.src = src;
if (loaded) loaded(img);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment