I am in a situation that needs be solve with this way; need convert a local variable to a global variable. There is an example returning image\'s r
This line,
console.log( pic_real_width + 'x' + pic_real_height );
does not wait for these lines
pic_real_width = this.width;
pic_real_height = this.height;
console.log( pic_real_width + 'x' + pic_real_height );
// -- returns true 570x320 --
to execute, because its asynchronous.
Thus,
console.log( pic_real_width + 'x' + pic_real_height ); executes before callback function gets called (i.e. before you set the width and height ).
Since, you havent defined them already, they show undefined.
A trivial solution would be,
$('
').attr('src', $(img).attr('src')).load(function() {
pic_real_width = this.width;
pic_real_height = this.height;
console.log( pic_real_width + 'x' + pic_real_height );
// -- returns true 570x320 --
restOfMyProcessing();
});
function restOfMyProcessing() {
console.log( pic_real_width + 'x' + pic_real_height );
}