Your original image
variable is not out of scope; variables are visible to all functions defined within the same block, even if the functions are defined within other functions. That is, a variable's scope is the function it is defined in. If there are variables of the same name across various functions, the inner-scoped function will have a new reference for that scope and no longer reference the outer function's value.
However, the original image
variable is shadowed by another variable also called image
in the innermost scope, the function(result,image)
you pass to largeImage.save().then()
. If you still need a reference to the outer image
variable, you should rename your inner image
variable to something else.
Since that innermost image
variable is undefined
, it looks to be a leftover from a copy+paste, and might not even belong on the parameter list of function(result,image)
in the first place.