Uname: Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
Software: LiteSpeed
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.213.251.212
Your Ip: 3.14.247.255
User: allssztx (535) | Group: allssztx (533)
Safe Mode: OFF
Disable Function:
NONE

name : image-dimensions.php
<?php

namespace ImageOptimization\Classes\Image;

use ImageOptimization\Classes\Logger;

use Imagick;
use stdClass;
use Throwable;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

class Image_Dimensions {
	/**
	 * @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 = 0;
		$output->height = 0;

		if ( $dimensions ) {
			$output->width = $dimensions[0];
			$output->height = $dimensions[1];

			return $output;
		}

		if ( class_exists( 'Imagick' ) ) {
			try {
				$im = new Imagick( $file_path );
				$image_geometry = $im->getImageGeometry();
				$im->clear();

				$output->width = $image_geometry['width'];
				$output->height = $image_geometry['height'];
			} catch ( Throwable $t ) {
				Logger::log(
					Logger::LEVEL_ERROR,
					'AVIF image dimensions calculation error: ' . $t->getMessage()
				);
			}
		}

		return $output;
	}
}
© 2025 GrazzMean-Shell