Extract common code from Path::buildImage{Path,Url}().