PHP Class Jetpack_PostImages, jetpack

Includes a few different methods, all of which return a similar-format array containing details of any images found. Everything can (should) be called statically, it's just a function-bucket. You can also call Jetpack_PostImages::get_image() to cycle through all of the methods until one of them finds something useful. This file is included verbatim in Jetpack
Afficher le fichier Open project: automattic/jetpack Class Usage Examples

Méthodes publiques

Méthode Description
fit_image_url ( string $src, $width, $height ) : string Takes an image URL and pixel dimensions then returns a URL for the resized and croped image.
from_attachment ( $post_id, $width = 200, $height = 200 ) Get attachment images for a specified post and return them. Also make sure their dimensions are at or above a required minimum.
from_blavatar ( integer $post_id, integer $size = 96 ) : Array
from_gallery ( $post_id ) If a gallery is detected, then get all the images from it.
from_gravatar ( integer $post_id, integer $size = 96, string $default = false ) : Array
from_html ( mixed $html_or_id ) : Array Very raw -- just parse the HTML and pull out any/all img tags and return their src
from_slideshow ( $post_id, $width = 200, $height = 200 ) If a slideshow is embedded within a post, then parse out the images involved and return them
from_thumbnail ( integer $post_id, $width = 200, $height = 200 ) : Array Check if a Featured Image is set for this post, and return it in a similar format to the other images?_from_*() methods.
get_image ( integer $post_id, array $args = [] ) : Array Run through the different methods that we have available to try to find a single good display image for this post.
get_images ( integer $post_id, array $args = [] ) : Array Get an array containing a collection of possible images for this post, stopping once we hit a method that returns something useful.

Method Details

fit_image_url() static public méthode

Takes an image URL and pixel dimensions then returns a URL for the resized and croped image.
static public fit_image_url ( string $src, $width, $height ) : string
$src string
Résultat string Transformed image URL

from_attachment() static public méthode

Get attachment images for a specified post and return them. Also make sure their dimensions are at or above a required minimum.
static public from_attachment ( $post_id, $width = 200, $height = 200 )

from_blavatar() static public méthode

static public from_blavatar ( integer $post_id, integer $size = 96 ) : Array
$post_id integer The post ID to check
$size integer
Résultat Array containing details of the image, or empty array if none.

from_gravatar() static public méthode

static public from_gravatar ( integer $post_id, integer $size = 96, string $default = false ) : Array
$post_id integer The post ID to check
$size integer
$default string The default image to use.
Résultat Array containing details of the image, or empty array if none.

from_html() static public méthode

Very raw -- just parse the HTML and pull out any/all img tags and return their src
static public from_html ( mixed $html_or_id ) : Array
$html_or_id mixed The HTML string to parse for images, or a post id
Résultat Array containing images

from_slideshow() static public méthode

If a slideshow is embedded within a post, then parse out the images involved and return them
static public from_slideshow ( $post_id, $width = 200, $height = 200 )

from_thumbnail() static public méthode

Check if a Featured Image is set for this post, and return it in a similar format to the other images?_from_*() methods.
static public from_thumbnail ( integer $post_id, $width = 200, $height = 200 ) : Array
$post_id integer The post ID to check
Résultat Array containing details of the Featured Image, or empty array if none.

get_image() static public méthode

Run through the different methods that we have available to try to find a single good display image for this post.
static public get_image ( integer $post_id, array $args = [] ) : Array
$post_id integer
$args array Other arguments (currently width and height required for images where possible to determine)
Résultat Array containing details of the best image to be used

get_images() static public méthode

Get an array containing a collection of possible images for this post, stopping once we hit a method that returns something useful.
static public get_images ( integer $post_id, array $args = [] ) : Array
$post_id integer
$args array Optional args, see defaults list for details
Résultat Array containing images that would be good for representing this post