WP_Image_Editor_GD::rotate()publicWP 3.5.0

Rotates current image counter-clockwise by $angle. Ported from image-edit.php

Method of the class: WP_Image_Editor_GD{}

No Hooks.

Return

true|WP_Error.

Usage

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

Changelog

Since 3.5.0 Introduced.

WP_Image_Editor_GD::rotate() code WP 6.5.2

public function rotate( $angle ) {
	if ( function_exists( 'imagerotate' ) ) {
		$transparency = imagecolorallocatealpha( $this->image, 255, 255, 255, 127 );
		$rotated      = imagerotate( $this->image, $angle, $transparency );

		if ( is_gd_image( $rotated ) ) {
			imagealphablending( $rotated, true );
			imagesavealpha( $rotated, true );
			imagedestroy( $this->image );
			$this->image = $rotated;
			$this->update_size();
			return true;
		}
	}

	return new WP_Error( 'image_rotate_error', __( 'Image rotate failed.' ), $this->file );
}