WP_Image_Editor_GD::rotate( float $angle ): true|WP_Error

Rotates current image counter-clockwise by $angle.

Description

Ported from image-edit.php

Parameters

$anglefloatrequired

Return

true|WP_Error

Source

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 );
}

Changelog

VersionDescription
3.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.