I allow the user to insert an object, an image, and then i call a function on that object. What seems randomly to me, sometimes it works and sometimes not, I guess it has t
You cannot access the images width and height until after the images loads. Thats why the setTimeout works for you sometimes. Use the image.load() call back function to trigger the code you require to be run after the image has loaded.
var imgInner = jQuery('', {
src: img
}).load(function () {
jQuery(this).appendTo('#' + objId)
restoreSize(myNewImg, this);
//and so on
});