WP_Image_Editor_Imagick::rotate()publicWP 3.5.0

Rotates current image counter-clockwise by $angle.

Method of the class: WP_Image_Editor_Imagick{}

No Hooks.

Return

true|WP_Error.

Usage

$WP_Image_Editor_Imagick = new WP_Image_Editor_Imagick();
$WP_Image_Editor_Imagick->rotate( $angle );
$angle(float) (required)
-

Changelog

Since 3.5.0 Introduced.

WP_Image_Editor_Imagick::rotate() code WP 6.6.2

public function rotate( $angle ) {
	/**
	 * $angle is 360-$angle because Imagick rotates clockwise
	 * (GD rotates counter-clockwise)
	 */
	try {
		$this->image->rotateImage( new ImagickPixel( 'none' ), 360 - $angle );

		// Normalize EXIF orientation data so that display is consistent across devices.
		if ( is_callable( array( $this->image, 'setImageOrientation' ) ) && defined( 'Imagick::ORIENTATION_TOPLEFT' ) ) {
			$this->image->setImageOrientation( Imagick::ORIENTATION_TOPLEFT );
		}

		// Since this changes the dimensions of the image, update the size.
		$result = $this->update_size();
		if ( is_wp_error( $result ) ) {
			return $result;
		}

		$this->image->setImagePage( $this->size['width'], $this->size['height'], 0, 0 );
	} catch ( Exception $e ) {
		return new WP_Error( 'image_rotate_error', $e->getMessage() );
	}

	return true;
}