Note that thumbnailWidth/sourceRectangle.w is just scale (except that the Math.floor when computing thumbnailWidth will make it off by a bit).  Can't you just do scale*sourceRectangle.h here?