Return the canonical URL path for an image for the given region/size/
    rotation/quality/format API tranformation settings.

    See http://iiif.io/api/image/2.1/#canonical-uri-syntax
6214
def make_canonical_path(
        image_identifier, image_width, image_height,
        region, size, rotation, quality, format_str
):
    
    original_aspect_ratio = float(image_width) / image_height

    if (
        region == 'full' or
        # Use 'full' if 'square' is requested for an already square image
        (region == 'square' and image_width == image_height) or
        # Use 'full' if region exactly matches image dimensions
        (region == (0, 0, image_width, image_height))
    ):
        canonical_region = 'full'
    else:
        # Use explicit x,y,width,height region settings
        canonical_region = ','.join(map(str, region))

    if size in ['full', 'max']:
        canonical_size = 'full'
    elif (region[2:] == size and (image_width, image_height) == size):
        # Use 'full' if result image dimensions are unchanged from original
        # and are also unchanged from the region operation's output
        canonical_size = 'full'
    elif float(size[0]) / size[1] == original_aspect_ratio:
        # w, syntax for images scaled to maintain the aspect ratio
        canonical_size = '%d,' % size[0]
    else:
        # Full with,height size if aspect ratio is changed
        canonical_size = ','.join(map(str, size))

    canonical_rotation = ''
    if rotation[0]:
        # Image is mirrored
        canonical_rotation += '!'
    canonical_rotation += '%d' % rotation[1]

    canonical_quality = quality

    canonical_format = format_str

    return reverse(
        'iiif_image_api',
        args=[image_identifier, canonical_region, canonical_size,
              canonical_rotation, canonical_quality, canonical_format]
    )
1236621
protected String getRewrittenImagePath(String originalCssPath, String newCssPath, String url) throws IOException {

		String imgUrl = null;

		// Retrieve the current CSS file from which the CSS image is referenced
		boolean generatedImg = false;
		if (binaryRsHandler != null) {
			GeneratorRegistry imgRsGeneratorRegistry = binaryRsHandler.getConfig().getGeneratorRegistry();
			generatedImg = imgRsGeneratorRegistry.isGeneratedBinaryResource(url);
		}

		String fullImgPath = PathNormalizer.concatWebPath(originalCssPath, url);
		if (!generatedImg) {

			// Add image servlet path in the URL, if it's defined
			if (StringUtils.isNotEmpty(binaryServletPath)) {
				fullImgPath = binaryServletPath + JawrConstant.URL_SEPARATOR + fullImgPath;
			}
			imgUrl = PathNormalizer.getRelativeWebPath(PathNormalizer.getParentPath(newCssPath), fullImgPath);

		} else {
			imgUrl = url;
		}

		return imgUrl;
	}
277080
function getCanonicalUrl(url) {
  // Trim the #fragment. We are unique to query string, though.
  var hashIndex = url.indexOf('#');
  if (hashIndex != -1) {
    url = url.substring(0, hashIndex);
  }
  return url;
}
1169195
def url_path
      # Get the path component of the URL as a relative path
      filename = URI.parse(url).path
      filename.slice!(0) # Remove the leading /
      # Return the path with '.json' extension if not already present
      filename.end_with?('.json') ? filename : "#{filename}.json"
    rescue URI::InvalidComponentError, URI::InvalidURIError
      # Return nil if the URL is invalid
      nil
    end
737680
def show
      @image = Picturesque::Image.find(params)
      @file = @image.process(params.slice(:size, :quality, :format))

      setup_canonical_link

      expires_in 3.years, public: @file
      send_file @file.path, disposition: Picturesque::Image::DISPOSITION
    end
902224
def _image_url(image, dst_color=None, src_color=None):
    
    if src_color and dst_color:
        if not Image:
            raise Exception("Images manipulation require PIL")
    file = StringValue(image).value
    path = None
    if callable(STATIC_ROOT):
        try:
            _file, _storage = list(STATIC_ROOT(file))[0]
            d_obj = _storage.modified_time(_file)
            filetime = int(time.mktime(d_obj.timetuple()))
            if dst_color:
                path = _storage.open(_file)
        except:
            filetime = 'NA'
    else:
        _path = os.path.join(STATIC_ROOT, file)
        if os.path.exists(_path):
            filetime = int(os.path.getmtime(_path))
            if dst_color:
                path = open(_path, 'rb')
        else:
            filetime = 'NA'
    BASE_URL = STATIC_URL
    if path:
        src_color = tuple(int(round(c)) for c in ColorValue(
            src_color).value[:3]) if src_color else (0, 0, 0)
        dst_color = [int(round(c)) for c in ColorValue(dst_color).value[:3]]

        file_name, file_ext = os.path.splitext(
            os.path.normpath(file).replace('\\', '_').replace('/', '_'))
        key = (filetime, src_color, dst_color)
        key = file_name + '-' + base64.urlsafe_b64encode(
            hashlib.md5(repr(key)).digest()).rstrip('=').replace('-', '_')
        asset_file = key + file_ext
        asset_path = os.path.join(ASSETS_ROOT, asset_file)

        if os.path.exists(asset_path):
            file = asset_file
            BASE_URL = ASSETS_URL
            filetime = int(os.path.getmtime(asset_path))
        else:
            image = Image.open(path)
            image = image.convert("RGBA")
            pixdata = image.load()
            for y in xrange(image.size[1]):
                for x in xrange(image.size[0]):
                    if pixdata[x, y][:3] == src_color:
                        new_color = tuple(dst_color + [pixdata[x, y][3]])
                        pixdata[x, y] = new_color
            try:
                image.save(asset_path)
                file = asset_file
                BASE_URL = ASSETS_URL
            except IOError:
                log.exception("Error while saving image")
    url = 'url("%s%s?_=%s")' % (BASE_URL, file, filetime)
    return StringValue(url)
1133205
def url(self, **params):
        
        self._setattrs(**params)
        path = self.baseurl + self.quote(self.identifier) + "/"
        if (self.info):
            # info request
            path += "info"
            format = self.format if self.format else "json"
        else:
            # region
            if self.region:
                region = self.region
            elif self.region_xywh:
                region = "%d,%d,%d,%d" % tuple(self.region_xywh)
            else:
                region = "full"
            # size
            if self.size:
                size = self.size
            elif self.size_wh:
                if (self.size_wh[0] is None):
                    size = ",%d" % (self.size_wh[1])
                elif (self.size_wh[1] is None):
                    size = "%d," % (self.size_wh[0])
                else:
                    size = "%d,%d" % (self.size_wh[0], self.size_wh[1])
            elif (self.size_max and self.api_version >= '2.1'):
                size = 'max'
            else:
                size = "full"
            # rotation and quality
            rotation = self.rotation if self.rotation else "0"
            quality = self.quality if self.quality else self.default_quality
            # parameterized form
            path += self.quote(region) + "/" +\
                self.quote(size) + "/" +\
                self.quote(rotation) + "/" +\
                self.quote(quality)
            format = self.format
        if (format):
            path += "." + format
        return(path)
1247714
def image_url(self, width=None, height=None):
        
        width_ = width or self.random_int(max=1024)
        height_ = height or self.random_int(max=1024)
        placeholder_url = self.random_element(self.image_placeholder_services)
        return placeholder_url.format(width=width_, height=height_)
868886
def best_url(self, size=None, external=False):
        '''
        
        '''
        if not self.thumbnail_sizes:
            return self.url
        elif not size:
            self.thumbnail_sizes.sort()
            best_size = self.thumbnail_sizes[-1]
        else:
            self.thumbnail_sizes.sort()
            index = bisect.bisect_left(self.thumbnail_sizes, size)
            if index >= len(self.thumbnail_sizes):
                best_size = self.thumbnail_sizes[-1]
            else:
                best_size = self.thumbnail_sizes[index]
        filename = self.thumbnail(best_size)
        return self.fs.url(filename, external=external) if filename else None
1232727
public static String canonical(File p) {
		try {
			return p.getCanonicalPath();
		} catch (IOException e) {
			String x = p.getAbsolutePath();
			return x == null ? p.getPath() : x;
		}
	}
1123149
def thumbnail_url(options = {})
      return if picture.nil?

      crop = crop_values_present? || content.settings_value(:crop, options)
      size = render_size || content.settings_value(:size, options)

      options = {
        size: thumbnail_size(size, crop),
        crop: !!crop,
        crop_from: crop_from.presence,
        crop_size: crop_size.presence,
        flatten: true,
        format: picture.image_file_format
      }

      picture.url(options)
    end
809332
private String getAdaptiveUrl(FileLink fileLink, int dimen) {
        ResizeTask resizeTask = new ResizeTask.Builder()
                .fit("crop")
                .align("center")
                .width(dimen)
                .height(dimen)
                .build();

        return fileLink.imageTransform().addTask(resizeTask).url();
    }
787387
def core__get_application_logo_sidebar_path
      dir = "#{core__get_application_root_path}/app/assets/images/lato/"
      if File.exist?("#{dir}/logo_sidebar.svg")
        return 'lato/logo_sidebar.svg'
      elsif File.exist?("#{dir}/logo_sidebar.png")
        return 'lato/logo_sidebar.png'
      elsif File.exist?("#{dir}/logo_sidebar.jpg")
        return 'lato/logo_sidebar.jpg'
      elsif File.exist?("#{dir}/logo_sidebar.gif")
        return 'lato/logo_sidebar.gif'
      end
      core__get_application_logo_path
    end
1232066
def uri_to_path(uri)
    return unless uri.is_a?(URI)

    # CGI.unescape doesn't handle space rules properly in uri paths
    # URI.unescape does, but returns strings in their original encoding
    path = URI.unescape(uri.path.encode(Encoding::UTF_8))

    if Puppet::Util::Platform.windows? && uri.scheme == 'file'
      if uri.host
        path = "//#{uri.host}" + path # UNC
      else
        path.sub!(/^\//, '')
      end
    end

    path
  end
967537
function getCanonicalPath(path) {
        path = path.replace(/\//g, '\\');
        path = path.replace(/\\\\/g, '\\');
        return path;
    }
829991
def get_avatar_url(self, size=2):
        
        hashbytes = self.get_ps('avatar_hash')

        if hashbytes != "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000":
            ahash = hexlify(hashbytes).decode('ascii')
        else:
            ahash = 'fef49e7fa7e1997310d705b2a6158ff8dc1cdfeb'

        sizes = {
            0: '',
            1: '_medium',
            2: '_full',
        }
        url = "http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/%s/%s%s.jpg"

        return url % (ahash[:2], ahash, sizes[size])
399525
def do_GET_body(self):
        """"""
        iiif = self.iiif
        if (len(self.path) > 1024):
            raise IIIFError(code=414,
                            text="URI Too Long: Max 1024 chars, got %d\n" % len(self.path))
        try:
            # self.path has leading / then identifier/params...
            self.path = self.path.lstrip('/')
            sys.stderr.write("path = %s" % (self.path))
            iiif.parse_url(self.path)
        except Exception as e:
            # Something completely unexpected => 500
            raise IIIFError(code=500,
                            text="Internal Server Error: unexpected exception parsing request (" + str(e) + ")")
        # Now we have a full iiif request
        if (re.match('[\w\.\-]+$', iiif.identifier)):
            file = os.path.join(TESTIMAGE_DIR, iiif.identifier)
            if (not os.path.isfile(file)):
                images_available = ""
                for image_file in os.listdir(TESTIMAGE_DIR):
                    if (os.path.isfile(os.path.join(TESTIMAGE_DIR, image_file))):
                        images_available += "  " + image_file + "\n"
                raise IIIFError(code=404, parameter="identifier",
                                text="Image resource '" + iiif.identifier + "' not found. Local image files available:\n" + images_available)
        else:
            raise IIIFError(code=404, parameter="identifier",
                            text="Image resource '" + iiif.identifier + "' not found. Only local test images and http: URIs for images are supported.\n")
        # Now know image is OK
        manipulator = IIIFRequestHandler.manipulator_class()
        # Stash manipulator object so we can cleanup after reading file
        self.manipulator = manipulator
        self.compliance_uri = manipulator.compliance_uri
        if (iiif.info):
            # get size
            manipulator.srcfile = file
            manipulator.do_first()
            # most of info.json comes from config, a few things
            # specific to image
            i = IIIFInfo()
            i.identifier = self.iiif.identifier
            i.width = manipulator.width
            i.height = manipulator.height
            import io
            return(io.StringIO(i.as_json()), "application/json")
        else:
            (outfile, mime_type) = manipulator.derive(file, iiif)
            return(open(outfile, 'r'), mime_type)