namespace ImageOptimization\Classes\Image;
use ImageOptimization\Classes\Logger;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
* @param string $file_path
* @return stdClass{width: int, height: int}
public static function get_by_path( string $file_path ): stdClass {
$dimensions = wp_getimagesize( $file_path );
$output = new stdClass();
$output->width = $dimensions[0];
$output->height = $dimensions[1];
if ( class_exists( 'Imagick' ) ) {
$im = new Imagick( $file_path );
$image_geometry = $im->getImageGeometry();
$output->width = $image_geometry['width'];
$output->height = $image_geometry['height'];
} catch ( Throwable $t ) {
'AVIF image dimensions calculation error: ' . $t->getMessage()