\Jetpack_PostImages

Useful for finding an image to display alongside/in representation of a specific post.

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

Summary

Methods
Properties
Constants
from_slideshow()
from_gallery()
from_attachment()
from_thumbnail()
from_html()
from_blavatar()
from_gravatar()
get_image()
get_images()
fit_image_url()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

from_slideshow()

from_slideshow( $post_id,  $width,  $height)

If a slideshow is embedded within a post, then parse out the images involved and return them

Parameters

$post_id
$width
$height

from_gallery()

from_gallery( $post_id)

If a gallery is detected, then get all the images from it.

Parameters

$post_id

from_attachment()

from_attachment( $post_id,  $width,  $height)

Get attachment images for a specified post and return them. Also make sure their dimensions are at or above a required minimum.

Parameters

$post_id
$width
$height

from_thumbnail()

from_thumbnail(int $post_id,  $width,  $height) : Array

Check if a Featured Image is set for this post, and return it in a similar format to the other images?_from_*() methods.

Parameters

int $post_id

The post ID to check

$width
$height

Returns

Array —

containing details of the Featured Image, or empty array if none.

from_html()

from_html(mixed $html_or_id) : Array

Very raw -- just parse the HTML and pull out any/all img tags and return their src

Parameters

mixed $html_or_id

The HTML string to parse for images, or a post id

Returns

Array —

containing images

from_blavatar()

from_blavatar(int $post_id, int $size) : Array

Parameters

int $post_id

The post ID to check

int $size

Returns

Array —

containing details of the image, or empty array if none.

from_gravatar()

from_gravatar(int $post_id, int $size, string $default) : Array

Parameters

int $post_id

The post ID to check

int $size
string $default

The default image to use.

Returns

Array —

containing details of the image, or empty array if none.

get_image()

get_image(int $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.

Parameters

int $post_id
array $args

Other arguments (currently width and height required for images where possible to determine)

Returns

Array —

containing details of the best image to be used

get_images()

get_images(int $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.

Parameters

int $post_id
array $args

Optional args, see defaults list for details

Returns

Array —

containing images that would be good for representing this post

fit_image_url()

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.

Parameters

string $src
$width
$height

Returns

string —

Transformed image URL