diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php index 34c0453ff693a..5bd845457f0e4 100644 --- a/src/wp-includes/class-wp-image-editor-gd.php +++ b/src/wp-includes/class-wp-image-editor-gd.php @@ -435,31 +435,22 @@ public function rotate( $angle ) { * * @param bool $horz Flip along Horizontal Axis. * @param bool $vert Flip along Vertical Axis. - * @return true|WP_Error + * @return bool|WP_Error */ 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; + if ( ! is_gd_image( $this->image ) ) { + return new WP_Error( 'image_flip_error', __( 'Image flip failed.' ), $this->file ); + } - return true; - } + if ( $horz && $vert ) { + return imageflip( $this->image, IMG_FLIP_BOTH ); + } elseif ( $horz ) { + return imageflip( $this->image, IMG_FLIP_VERTICAL ); + } elseif ( $vert ) { + return imageflip( $this->image, IMG_FLIP_HORIZONTAL ); } - return new WP_Error( 'image_flip_error', __( 'Image flip failed.' ), $this->file ); + return true; } /**