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<string|int, mixed>
We need to track if uncropped was on or off when generating the images.
adjust_intermediate_image_sizes()  : array<string|int, mixed>
Only regenerate images for the requested size.
dismiss_regenerating_notice()  : mixed
Dismiss notice and cancel jobs.
filter_image_get_intermediate_size()  : array<string|int, mixed>
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<string|int, mixed>
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<string|int, mixed>
Get full size image dimensions.
get_image()  : array<string|int, mixed>|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<string|int, mixed> $meta_data) : array<string|int, mixed>
Parameters
$meta_data : array<string|int, mixed>

Array of meta data.

Return values
array<string|int, mixed>

adjust_intermediate_image_sizes()

Only regenerate images for the requested size.

public static adjust_intermediate_image_sizes(array<string|int, mixed> $sizes) : array<string|int, mixed>
Parameters
$sizes : array<string|int, mixed>

Array of image sizes.

Return values
array<string|int, mixed>

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<string|int, mixed> $data, int $attachment_id, string $size) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>

Size data.

$attachment_id : int

Attachment ID.

$size : string

Size name.

Return values
array<string|int, mixed>

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_regenerate_images()

Regenerate images if the settings have changed since last re-generation.

public static maybe_regenerate_images() : void
Return values
void

maybe_resize_image()

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

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

Properties of the image.

$attachment_id : int

Attachment ID.

$size : string|array<string|int, mixed>

Image size.

$icon : bool

If icon or not.

Return values
array<string|int, mixed>

queue_image_regeneration()

Get list of images and queue them for regeneration

public static queue_image_regeneration() : void
Return values
void

image_size_matches_settings()

See if an image's dimensions match actual settings.

protected static image_size_matches_settings(array<string|int, mixed> $image, string $size) : bool
Parameters
$image : array<string|int, mixed>

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<string|int, mixed>
Parameters
$attachment_id : int

Attachment ID of image.

Return values
array<string|int, mixed>Width 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<string|int, mixed>|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<string|int, mixed>|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<string|int, mixed> $image, string $size, bool $icon) : string
Parameters
$attachment_id : int

Attachment ID.

$image : array<string|int, mixed>

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.