WC_Regenerate_Images::get_image()
Generate the thumbnail filename and dimensions for a given file.
Method of the class: WC_Regenerate_Images{}
No Hooks.
Return
Array|false
. An 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.
Usage
$result = WC_Regenerate_Images::get_image( $fullsizepath, $thumbnail_width, $thumbnail_height, $crop );
- $fullsizepath(string) (required)
- Path to full size image.
- $thumbnail_width(int) (required)
- The width of the thumbnail.
- $thumbnail_height(int) (required)
- The height of the thumbnail.
- $crop(true|false) (required)
- Whether to crop or not.
WC_Regenerate_Images::get_image() WC Regenerate Images::get image code WC 9.5.1
private static function get_image( $fullsizepath, $thumbnail_width, $thumbnail_height, $crop ) { list( $fullsize_width, $fullsize_height ) = getimagesize( $fullsizepath ); $dimensions = image_resize_dimensions( $fullsize_width, $fullsize_height, $thumbnail_width, $thumbnail_height, $crop ); $editor = wp_get_image_editor( $fullsizepath ); if ( is_wp_error( $editor ) ) { return false; } if ( ! $dimensions || ! is_array( $dimensions ) ) { return false; } list( , , , , $dst_w, $dst_h ) = $dimensions; $suffix = "{$dst_w}x{$dst_h}"; $file_ext = strtolower( pathinfo( $fullsizepath, PATHINFO_EXTENSION ) ); return array( 'filename' => $editor->generate_filename( $suffix, null, $file_ext ), 'width' => $dst_w, 'height' => $dst_h, ); }