Title: WP_Image_Editor_GD::flip
Published: April 25, 2014
Last modified: February 24, 2026

---

# WP_Image_Editor_GD::flip( bool $horz, bool $vert ): true|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#wp--skip-link--target)

Flips current image.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#parameters)󠁿

 `$horz`boolrequired

Flip along Horizontal Axis.

`$vert`boolrequired

Flip along Vertical Axis.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#return)󠁿

 true|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#source)󠁿

    ```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 ) ) {
    			if ( PHP_VERSION_ID < 80000 ) { // imagedestroy() has no effect as of PHP 8.0.
    				imagedestroy( $this->image );
    			}

    			$this->image = $dst;

    			return true;
    		}
    	}

    	return new WP_Error( 'image_flip_error', __( 'Image flip failed.' ), $this->file );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-image-editor-gd.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-image-editor-gd.php#L448)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-image-editor-gd.php#L448-L471)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#related)󠁿

| Uses | Description | 
| [is_gd_image()](https://developer.wordpress.org/reference/functions/is_gd_image/)`wp-includes/media.php` |

Determines whether the value is an acceptable type for GD image functions.

  | 
| [wp_imagecreatetruecolor()](https://developer.wordpress.org/reference/functions/wp_imagecreatetruecolor/)`wp-includes/media.php` |

Creates a new GD image resource with transparency support.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 2 more](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/flip/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_image_editor_gd%2Fflip%2F)
before being able to contribute a note or feedback.