WP_Image_Editor_GD::rotate() WordPress Method

The rotate() method is used to rotate an image by a specified number of degrees. This is useful for correcting images that are not properly oriented.

WP_Image_Editor_GD::rotate( float $angle ) #

Rotates current image counter-clockwise by $angle.


Description

Ported from image-edit.php


Top ↑

Parameters

$angle

(float)(Required)


Top ↑

Return

(true|WP_Error)


Top ↑

Source

File: wp-includes/class-wp-image-editor-gd.php

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


Top ↑

Changelog

Changelog
VersionDescription
3.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.