You can just use $file->getUrl() method here, as wfReplaceImageServer function is already used internally by GlobalFile:getUrl method