Get URL for an image in the media library
@param string $path
@param string $size (size keys that you've passed to add_image_size)
@return string Relative URL
6468
public static function media($path, $size) {
    // Which image size was requested?
    global $_wp_additional_image_sizes;
    $image_size = $_wp_additional_image_sizes[$size];
    
    // Get the path info
    $pathinfo = pathinfo($path);
    $fname = $pathinfo['basename'];
    $fext = $pathinfo['extension'];
    $dir = $pathinfo['dirname'];
    $fdir = realpath(str_replace('//', '/', ABSPATH.$dir)).'/';
    
    // Filename without any size suffix or extension (e.g. without -144x200.jpg)
    $fname_prefix = preg_replace('/(?:-\d+x\d+)?\.'.$fext.'$/i', '', $fname);
    $out_fname = sprintf(
      '%s-%sx%s.%s',
      $fname_prefix,
      $image_size['width'],
      $image_size['height'],
      $fext
    );
    
    // See if the file that we're predicting exists
    // If so, we can avoid a call to the database
    $fpath = $fdir.$out_fname;
    if(file_exists($fpath)) {
      return sprintf(
        '%s/%s',
        $pathinfo['dirname'],
        $out_fname
      );
    }
    
    // Can't find the file? Figure out the correct path from the database
    global $wpdb;
    $guid = site_url().$dir.'/'.$fname_prefix.'.'.$fext;
    $prepared = $wpdb->prepare(
      "SELECT
        pm.meta_value
      FROM $wpdb->posts p
      INNER JOIN $wpdb->postmeta pm
        ON p.ID = pm.post_id
      WHERE p.guid = %s
      AND pm.meta_key = '_wp_attachment_metadata'
      LIMIT 1",
      $guid
    );
    $row = $wpdb->get_row($prepared);
    if(is_object($row)) {
      $meta = unserialize($row->meta_value);
      if(isset($meta['sizes'][$size]['file'])) {
        $meta_fname = $meta['sizes'][$size]['file'];
        return sprintf(
          '%s/%s',
          $pathinfo['dirname'],
          $meta_fname
        );
      }
    }
    
    // Still nothing? Just return the path given
    return $path;
  }
217671
public function url( $path )
	{
		$adapter = $this->driver->getAdapter();

		if ( $adapter instanceof AwsS3Adapter )
		{
			$path = $adapter->getPathPrefix() . $path;

			return $adapter->getClient()->getObjectUrl( $adapter->getBucket(), $path );
		}
		elseif ( $adapter instanceof LocalAdapter )
		{
			return '/storage/' . $path;
		}
		elseif ( method_exists( $adapter, 'getUrl' ) )
		{
			return $adapter->getUrl( $path );
		}
		else
		{
			throw new RuntimeException( 'This driver does not support retrieving URLs.' );
		}
	}
1141004
public function pathFilenameOfResizedImage($filename, $width, $height)
    {
        $path                      = $this->pathOfImagesResizedFolder();
        $filenameWithNoExtension   = $this->filenameWithNoExtension($filename);
        $filenameWithExtensionOnly = $this->filenameWithExtensionOnly($filename);

        $resizedFilename  = $path;
        $resizedFilename .= "/";
        $resizedFilename .= $filenameWithNoExtension;
        $resizedFilename .= '-';
        $resizedFilename .= $width;
        $resizedFilename .= 'x';
        $resizedFilename .= $height;
        $resizedFilename .= '.';
        $resizedFilename .= $filenameWithExtensionOnly;

        return $resizedFilename;
    }
920160
public function getThumbnailUrl(string $itemId, int $size = 75):array
    {
        $parameters = $this->buildHttpQuery(
            [
                'size'     => $size,
                'redirect' => false,
            ]
        );

        return $this->get("Items({$itemId})/Thumbnail?{$parameters}");
    }
22415
public function getUrl($path)
    {
        if ($this->publish($path)) {
            $obj = $this->getFileObject($path);
            if ($url = $obj->getWebContentLink()) {
                return str_replace('export=download', 'export=media', $url);
            }
            if ($url = $obj->getWebViewLink()) {
                return $url;
            }
        }
        return false;
    }
1006726
public static function url($relative, $width, $height)
    {

        if (preg_match('/^https?:\/\//i', $relative)) {

            return static::fromUrl($relative, $width, $height);

        } elseif (strlen(parse_url($relative, PHP_URL_QUERY)) > 0) {

            $relative = static::$config['base_uri'] . $relative;

            return static::fromUrl($relative, $width, $height);
        }

        return static::fromFile($relative, $width, $height);
    }
925757
public function getImageUrl(Media $media, $basepath)
    {
        if ($media->getUrl() === parse_url($media->getUrl(), PHP_URL_PATH)) {
            return $basepath . $media->getUrl();
        }

        return $media->getUrl();
    }
995006
public function getThumbnail($size) {
		switch ($size) {
			case 'thumb':
				$thumb = $this->thumbnail;
				break;
			case 'small':
				$thumb = $this->smallthumb;
				break;
			case 'large':
				$thumb = $this->largethumb;
				break;
			default:
				return '';
				break;
		}

		if (!$thumb) {
			return '';
		}

		$file = new ElggFile();
		$file->owner_guid = $this->getOwnerGUID();
		$file->setFilename($thumb);
		return $file->grabFile();
	}
901529
public function getUrl($path = null)
    {
        $path = $path ?: $this->path;

        if ($this->package->config('public_storage', false)) {
            // If file has public access enabled, we simply can try return storage
            // url to file.
            try {
                $useAbsolute = $this->package->config('absolute_url', false);
                $absolute = $this->storage->url($path);

                if ($useAbsolute) return $absolute;

                $relative = parse_url($absolute, PHP_URL_PATH);

                return '/' . trim($relative, '\\/');
            } catch (\Exception $ex) {
                // Some drivers does not support url method (like ftp), so we
                // simply continue and generate crip url to our controller.
            }
        }

        $service = new UrlService($this->package);
        if ($this->metadata->isFile()) {
            return $service->file($path);
        }

        return $service->folder($path);
    }
395207
public function getAvatar($size = self::AVATAR_MIDDLE)
    {
        $size = in_array($size, ['big', 'middle', 'small']) ? $size : 'big';
        if ($this->getIsAvatar()) {
            $avatarFileName = "_avatar_$size.jpg";
            return $this->getAvatarUrl($this->id) . $avatarFileName;
        } else {
            switch ($size) {
                case 'big':
                    $avatarUrl = '/img/no_avatar_big.gif';
                    break;
                case 'middle':
                    $avatarUrl = '/img/no_avatar_middle.gif';
                    break;
                case 'small':
                    $avatarUrl = '/img/no_avatar_small.gif';
                    break;
                default:
                    $avatarUrl = '/img/no_avatar_big.gif';
            }
            if (Yii::getAlias('@webroot', false)) {
                $baseUrl = UserAsset::register(Yii::$app->view)->baseUrl;
                return Url::to($baseUrl . $avatarUrl, true);
            } else {
                return '';
            }
        }
    }
492284
protected function getImageDimensions($type, $size)
	{
		$pathToImage = public_path($this->getImageConfig($type, $size, 'dir') . $this->$type);
		if (is_file($pathToImage) && file_exists($pathToImage))
		{
			list($width, $height) = getimagesize($pathToImage);
		}
		else
		{
			$width = $height = false;
		}
		return array($width, $height);
	}
461540
public function imageUrl($width, $height, $fit): string
    {
        // Sign the URL, to protect against mass-resize attacks.
        $glide_key = Site::getPreference('glide-key');
        if (empty($glide_key)) {
            $glide_key = bin2hex(random_bytes(128));
            Site::setPreference('glide-key', $glide_key);
        }

        if (Auth::accessLevel($this->media->tree()) > $this->media->tree()->getPreference('SHOW_NO_WATERMARK')) {
            $mark = 'watermark.png';
        } else {
            $mark = '';
        }

        $url_builder = UrlBuilderFactory::create(WT_BASE_URL, $glide_key);

        $url = $url_builder->getUrl('index.php', [
            'route'     => 'media-thumbnail',
            'xref'      => $this->media->xref(),
            'ged'       => $this->media->tree()->name(),
            'fact_id'   => $this->fact_id,
            'w'         => $width,
            'h'         => $height,
            'fit'       => $fit,
            'mark'      => $mark,
            'markh'     => '100h',
            'markw'     => '100w',
            'markalpha' => 25,
            'or'        => 0,
            // Intervention uses exif_read_data() which is very buggy.
        ]);

        return $url;
    }
1341430
public ThumbnailDownload getThumbnail(String path, ThumbnailSize size, ThumbnailFormat format) {
        OAuthRequest request = new OAuthRequest(Verb.GET, THUMBNAILS_URL + encode(path));

        if (size != THUMBNAIL_SIZE) {
            request.addQuerystringParameter("size", size.toString());
        }

        if (format != THUMBNAIL_FORMAT) {
            request.addQuerystringParameter("format", format.toString());
        }

        service.signRequest(accessToken, request);
        Response response = checkThumbnails(request.send());

        return new ThumbnailDownload(response, path, size, format);
    }
715031
public function iconUrl($image, $size = 16)
    {
        if (!$image) {
            return '';
        }

        $parts = explode(';', $image);
        $fileId = $parts[0];

        $src = $this->router->generate('frontendmedia_icon', ['fileId' => $fileId, 'size' => $size], UrlGeneratorInterface::ABSOLUTE_URL);

        return $src;
    }
340306
public function getCoverFile($size)
    {
        $coverFilename = $this->coverFilename;

        //get the extension
        $extension = explode('.', $coverFilename);
        $extension = array_pop($extension);

        //remove file extension
        $name = preg_replace('#\.[^.]*$#', '', $coverFilename);
        $coverFilename = $name.'_'.$size.'.'.$extension;

        return $coverFilename;
    }
65666
public function sizeUrl($size)
    {
        if (($this->base['return_format'] === 'array') && isset($this->base['value']['sizes'][$size])) {
            return $this->base['value']['sizes'][$size];
        } elseif ($this->base['return_format'] === 'id') {
            if ($src = wp_get_attachment_image_src($this->id(), $size)) {
                return $src[0];
            }
        }

        return '';
    }
1129490
static public function img($path, $with_version = true) {
        $url = $path;
        if($with_version) {
            $ver = self::cssVer();
            $url .= (strpos($url, '?') === false ? '?' : '&') . "version={$ver}";
        }
        return $url;
    }