Uname: Linux premium294.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
Software: LiteSpeed
PHP version: 8.1.32 [ PHP INFO ] PHP os: Linux
Server Ip: 104.21.96.1
Your Ip: 216.73.216.223
User: mjbynoyq (1574) | Group: mjbynoyq (1570)
Safe Mode: OFF
Disable Function:
NONE

name : wordpress-service.php
<?php
/**
 * Created by PhpStorm.
 * User: alex
 * Date: 4/4/19
 * Time: 3:51 PM
 */

class  Brizy_Editor_Asset_Crop_WordpressService implements Brizy_Editor_Asset_Crop_ServiceInterface {

	/**
	 * @var WP_Image_Editor
	 */
	private $imageEditor;

	/**
	 * @var string
	 */
	private $targetPath;

	/**
	 * Brizy_Editor_Asset_Crop_WordpressService constructor.
	 *
	 * @param $sourcePath
	 * @param $targetPath
	 *
	 * @throws Exception
	 */
	public function __construct( $sourcePath, $targetPath ) {

		if ( ! file_exists( $sourcePath ) ) {
			throw new Exception( 'Unable to crop media. Source file not found.' );
		}

		$this->targetPath  = $targetPath;
		$this->imageEditor = wp_get_image_editor( $sourcePath );

		if ( $this->imageEditor instanceof WP_Error ) {
			Brizy_Logger::instance()->error( $this->imageEditor->get_error_message(), array( $this->imageEditor ) );
			throw new Exception( "Unable to obtain the image editor" );
		}
	}

	/**
	 * @param int $offsetX
	 * @param int $offsetY
	 * @param int $width
	 * @param int $height
	 *
	 * @return bool
	 */
	public function crop( $offsetX, $offsetY, $width, $height ) {
		try {
			$this->imageEditor->crop( $offsetX, $offsetY, $width, $height );
		} catch ( Exception $e ) {
			Brizy_Logger::instance()->error( $e->getMessage(), [ $e ] );

			return false;
		}

		return true;
	}


	public function getSize() {
		try {
			return $this->imageEditor->get_size();
		} catch ( Exception $e ) {
			Brizy_Logger::instance()->error( $e->getMessage(), [ $e ] );
		}
	}

	/**
	 * @param int $width
	 * @param int $height
	 *
	 * @return bool
	 */
	public function resize( $width, $height ) {

		try {
			$this->imageEditor->resize( $width, $height );
		} catch ( Exception $e ) {
			Brizy_Logger::instance()->error( $e->getMessage(), [ $e ] );

			return false;
		}

		return true;
	}

	/**
	 * @throws Exception
	 */
	public function saveTargetImage() {
		$result = $this->imageEditor->save( $this->targetPath );

		if ( $result instanceof WP_Error ) {
			return false;
		}

		return true;
	}

}
© 2025 XylotrechusZ