WP_Image_Editor_GD::flip() WordPress Method

The flip() method is used to flip an image. It takes two parameters: the first is the path to the image, and the second is the mode. The mode can be either horizontal or vertical. This method can be used to create a mirror image of an image.

WP_Image_Editor_GD::flip( bool $horz, bool $vert ) #

Flips current image.


Parameters

$horz

(bool)(Required)Flip along Horizontal Axis.

$vert

(bool)(Required)Flip along Vertical Axis.


Top ↑

Return

(true|WP_Error)


Top ↑

Source

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

	public function flip( $horz, $vert ) {
		$w   = $this->size['width'];
		$h   = $this->size['height'];
		$dst = wp_imagecreatetruecolor( $w, $h );

		if ( is_gd_image( $dst ) ) {
			$sx = $vert ? ( $w - 1 ) : 0;
			$sy = $horz ? ( $h - 1 ) : 0;
			$sw = $vert ? -$w : $w;
			$sh = $horz ? -$h : $h;

			if ( imagecopyresampled( $dst, $this->image, 0, 0, $sx, $sy, $w, $h, $sw, $sh ) ) {
				imagedestroy( $this->image );
				$this->image = $dst;
				return true;
			}
		}

		return new WP_Error( 'image_flip_error', __( 'Image flip 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.