lib/ImageHelper.php
public static function analyze_url( $url ) {
		$result = array(
			'url' => $url, // the initial url
			'absolute' => URLHelper::is_absolute($url), // is the url absolute or relative (to home_url)
			'base' => 0, // is the image in uploads dir, or in content dir (theme or plugin)
			'subdir' => '', // the path between base (uploads or content) and file
			'filename' => '', // the filename, without extension
			'extension' => '', // the file extension
			'basename' => '', // full file name
		);
		$upload_dir = wp_upload_dir();
		$tmp = $url;
		if ( TextHelper::starts_with($tmp, ABSPATH) || TextHelper::starts_with($tmp, '/srv/www/') ) {
			// we've been given a dir, not an url
			$result['absolute'] = true;
			if ( TextHelper::starts_with($tmp, $upload_dir['basedir']) ) {
				$result['base'] = self::BASE_UPLOADS; // upload based
				$tmp = URLHelper::remove_url_component($tmp, $upload_dir['basedir']);
			}
			if ( TextHelper::starts_with($tmp, WP_CONTENT_DIR) ) {
				$result['base'] = self::BASE_CONTENT; // content based
				$tmp = URLHelper::remove_url_component($tmp, WP_CONTENT_DIR);
			}
		} else {
			if ( !$result['absolute'] ) {
				$tmp = untrailingslashit(network_home_url()).$tmp;
			}
			if ( URLHelper::starts_with($tmp, $upload_dir['baseurl']) ) {
				$result['base'] = self::BASE_UPLOADS; // upload based
				$tmp = URLHelper::remove_url_component($tmp, $upload_dir['baseurl']);
			} else if ( URLHelper::starts_with($tmp, content_url()) ) {
				$result['base'] = self::BASE_CONTENT; // content-based
				$tmp = self::theme_url_to_dir($tmp);
				$tmp = URLHelper::remove_url_component($tmp, WP_CONTENT_DIR);
			}
		}
		$parts = pathinfo($tmp);
		$result['subdir'] = ($parts['dirname'] === '/') ? '' : $parts['dirname'];
		$result['filename'] = $parts['filename'];
		$result['extension'] = strtolower($parts['extension']);
		$result['basename'] = $parts['basename'];
		return $result;
	}
public static function analyze_url( $url ) {
		$result = array(
			'url' => $url, // the initial url
			'absolute' => URLHelper::is_absolute($url), // is the url absolute or relative (to home_url)
			'base' => 0, // is the image in uploads dir, or in content dir (theme or plugin)
			'subdir' => '', // the path between base (uploads or content) and file
			'filename' => '', // the filename, without extension
			'extension' => '', // the file extension
			'basename' => '', // full file name
		);
		$upload_dir = wp_upload_dir();
		$tmp = $url;
		if ( TextHelper::starts_with($tmp, ABSPATH) || TextHelper::starts_with($tmp, '/srv/www/') ) {
			// we've been given a dir, not an url
			$result['absolute'] = true;
			if ( TextHelper::starts_with($tmp, $upload_dir['basedir']) ) {
				$result['base'] = self::BASE_UPLOADS; // upload based
				$tmp = URLHelper::remove_url_component($tmp, $upload_dir['basedir']);
			}
			if ( TextHelper::starts_with($tmp, WP_CONTENT_DIR) ) {
				$result['base'] = self::BASE_CONTENT; // content based
				$tmp = URLHelper::remove_url_component($tmp, WP_CONTENT_DIR);
			}
		} else {
			if ( !$result['absolute'] ) {
				$tmp = untrailingslashit(network_home_url()).$tmp;
			}
			if ( URLHelper::starts_with($tmp, $upload_dir['baseurl']) ) {
				$result['base'] = self::BASE_UPLOADS; // upload based
				$tmp = URLHelper::remove_url_component($tmp, $upload_dir['baseurl']);
			} else if ( URLHelper::starts_with($tmp, content_url()) ) {
				$result['base'] = self::BASE_CONTENT; // content-based
				$tmp = self::theme_url_to_dir($tmp);
				$tmp = URLHelper::remove_url_component($tmp, WP_CONTENT_DIR);
			}
		}
		$parts = pathinfo($tmp);
		$result['subdir'] = ($parts['dirname'] === '/') ? '' : $parts['dirname'];
		$result['filename'] = $parts['filename'];
		$result['extension'] = strtolower($parts['extension']);
		$result['basename'] = $parts['basename'];
		return $result;
	}
public static function analyze_url ( $ url ) { $ result = array ( 'url' => $ url , // the initial url 'absolute' => URLHelper :: is_absolute ( $ url ) , // is the url absolute or relative (to home_url) 'base' => 0 , // is the image in uploads dir, or in content dir (theme or plugin) 'subdir' => '' , // the path between base (uploads or content) and file 'filename' => '' , // the filename, without extension 'extension' => '' , // the file extension 'basename' => '' , // full file name ) ; $ upload_dir = wp_upload_dir ( ) ; $ tmp = $ url ; if ( TextHelper :: starts_with ( $ tmp , ABSPATH ) || TextHelper :: starts_with ( $ tmp , '/srv/www/' ) ) { // we've been given a dir, not an url $ result [ 'absolute' ] = true ; if ( TextHelper :: starts_with ( $ tmp , $ upload_dir [ 'basedir' ] ) ) { $ result [ 'base' ] = self :: BASE_UPLOADS ; // upload based $ tmp = URLHelper :: remove_url_component ( $ tmp , $ upload_dir [ 'basedir' ] ) ; } if ( TextHelper :: starts_with ( $ tmp , WP_CONTENT_DIR ) ) { $ result [ 'base' ] = self :: BASE_CONTENT ; // content based $ tmp = URLHelper :: remove_url_component ( $ tmp , WP_CONTENT_DIR ) ; } } else { if ( ! $ result [ 'absolute' ] ) { $ tmp = untrailingslashit ( network_home_url ( ) ) . $ tmp ; } if ( URLHelper :: starts_with ( $ tmp , $ upload_dir [ 'baseurl' ] ) ) { $ result [ 'base' ] = self :: BASE_UPLOADS ; // upload based $ tmp = URLHelper :: remove_url_component ( $ tmp , $ upload_dir [ 'baseurl' ] ) ; } else if ( URLHelper :: starts_with ( $ tmp , content_url ( ) ) ) { $ result [ 'base' ] = self :: BASE_CONTENT ; // content-based $ tmp = self :: theme_url_to_dir ( $ tmp ) ; $ tmp = URLHelper :: remove_url_component ( $ tmp , WP_CONTENT_DIR ) ; } } $ parts = pathinfo ( $ tmp ) ; $ result [ 'subdir' ] = ( $ parts [ 'dirname' ] === '/' ) ? '' : $ parts [ 'dirname' ] ; $ result [ 'filename' ] = $ parts [ 'filename' ] ; $ result [ 'extension' ] = strtolower ( $ parts [ 'extension' ] ) ; $ result [ 'basename' ] = $ parts [ 'basename' ] ; return $ result ; }
Takes in an URL and breaks it into components,
that will then be used in the different steps of image processing.
The image is expected to be either part of a theme, plugin, or an upload.

@param  string $url an URL (absolute or relative) pointing to an image
@return array       an array (see keys in code below)
Takes in an URL and breaks it into components that will then be used in the different steps of image processing . The image is expected to be either part of a theme plugin or an upload .