WooCommerce Code Reference

WC_Regenerate_Images
in package

Regenerate Images Class

Table of Contents

$background_process  : WC_Regenerate_Images_Request
Background process to regenerate all images
$regenerate_size  : string
Stores size being generated on the fly.
add_uncropped_metadata()  : array
We need to track if uncropped was on or off when generating the images.
adjust_intermediate_image_sizes()  : array
Only regenerate images for the requested size.
dismiss_regenerating_notice()  : mixed
Dismiss notice and cancel jobs.
filter_image_get_intermediate_size()  : array
If an intermediate size meta differs from the actual image size (settings were changed?) return false so the wrong size is not used.
init()  : mixed
Init function
is_regeneratable()  : bool
Ensure we are dealing with the correct image attachment
maybe_regenerate_images()  : void
Regenerate images if the settings have changed since last re-generation.
maybe_resize_image()  : array
Check if we should maybe generate a new image size if not already there.
queue_image_regeneration()  : void
Get list of images and queue them for regeneration
regenerating_notice()  : mixed
Show notice when job is running in background.
image_size_matches_settings()  : bool
See if an image's dimensions match actual settings.
get_full_size_image_dimensions()  : array
Get full size image dimensions.
get_image()  : array|false
Generate the thumbnail filename and dimensions for a given file.
resize_and_return_image()  : string
Regenerate the image according to the required size
unfiltered_image_downsize()  : string
Image downsize, without this classes filtering on the results.

Properties

Methods

add_uncropped_metadata()

We need to track if uncropped was on or off when generating the images.

public static add_uncropped_metadata(array $meta_data) : array
Parameters
$meta_data : array

Array of meta data.

Return values
array

adjust_intermediate_image_sizes()

Only regenerate images for the requested size.

public static adjust_intermediate_image_sizes(array $sizes) : array
Parameters
$sizes : array

Array of image sizes.

Return values
array

filter_image_get_intermediate_size()

If an intermediate size meta differs from the actual image size (settings were changed?) return false so the wrong size is not used.

public static filter_image_get_intermediate_size(array $data, int $attachment_id, string $size) : array
Parameters
$data : array

Size data.

$attachment_id : int

Attachment ID.

$size : string

Size name.

Return values
array

is_regeneratable()

Ensure we are dealing with the correct image attachment

public static is_regeneratable(int|WP_Post $attachment) : bool
Parameters
$attachment : int|WP_Post

Attachment object or ID.

Return values
bool

maybe_resize_image()

Check if we should maybe generate a new image size if not already there.

public static maybe_resize_image(array $image, int $attachment_id, string|array $size, bool $icon) : array
Parameters
$image : array

Properties of the image.

$attachment_id : int

Attachment ID.

$size : string|array

Image size.

$icon : bool

If icon or not.

Return values
array

image_size_matches_settings()

See if an image's dimensions match actual settings.

protected static image_size_matches_settings(array $image, string $size) : bool
Parameters
$image : array

Image dimensions array.

$size : string

Named size.

Return values
boolTrue if they match. False if they do not (may trigger regen).

get_full_size_image_dimensions()

Get full size image dimensions.

private static get_full_size_image_dimensions(int $attachment_id) : array
Parameters
$attachment_id : int

Attachment ID of image.

Return values
arrayWidth and height. Empty array if the dimensions cannot be found.

get_image()

Generate the thumbnail filename and dimensions for a given file.

private static get_image(string $fullsizepath, int $thumbnail_width, int $thumbnail_height, bool $crop) : array|false
Parameters
$fullsizepath : string

Path to full size image.

$thumbnail_width : int

The width of the thumbnail.

$thumbnail_height : int

The height of the thumbnail.

$crop : bool

Whether to crop or not.

Return values
array|falseAn array of the filename, thumbnail width, and thumbnail height, or false on failure to resize such as the thumbnail being larger than the fullsize image.

resize_and_return_image()

Regenerate the image according to the required size

private static resize_and_return_image(int $attachment_id, array $image, string $size, bool $icon) : string
Parameters
$attachment_id : int

Attachment ID.

$image : array

Original Image.

$size : string

Size to return for new URL.

$icon : bool

If icon or not.

Return values
string

unfiltered_image_downsize()

Image downsize, without this classes filtering on the results.

private static unfiltered_image_downsize(int $attachment_id, string $size) : string
Parameters
$attachment_id : int

Attachment ID.

$size : string

Size to downsize to.

Return values
stringNew image URL.