Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#23775 closed defect (bug) (fixed)

WP_Image_Editor Flip Method $horz and $vert arguments are backwards

Reported by: alconebay Owned by: ryan
Milestone: 3.6 Priority: normal
Severity: minor Version: 3.5.1
Component: Media Keywords: has-patch
Focuses: Cc:


The WP_Image_Editor class shows:

 * @param boolean $horz Horizontal Flip
 * @param boolean $vert Vertical Flip
abstract public function flip( $horz, $vert );

But changing the first argument to true flips the image vertically and the second argument, when true, flips the image horizontally.
Both imagemagick and GD are affected.

A fix for class-wp-image-editor-imagick.php would be reversing lines 366 and 369 (flopImage for $horz and flipImage for $vert)

A fix for class-wp-image-editor-gd.php would be reversing $horz and $vert on lines 292-295 like this (fixed):

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

I've verified these fixes.

Attachments (1)

23775.diff (1.7 KB) - added by dh-shredder 3 years ago.
Describe Flip Better

Download all attachments as: .zip

Change History (7)

@dh-shredder3 years ago

Describe Flip Better

comment:1 @dh-shredder3 years ago

I think the issue here is an understanding on what vertical and horizontal means.

You're right, the current comments make it confusing!

Horizontal means a flip along the horizontal axis.
Vertical means a flip along the vertical axis.

I've attached 23775.diff​, which revises the phpdoc to better explain what flips the booleans control.

comment:2 @dh-shredder3 years ago

  • Keywords has-patch added; needs-patch removed

comment:3 @markoheijnen3 years ago

  • Milestone changed from Awaiting Review to 3.6

comment:4 @dh-shredder3 years ago

  • Component changed from General to Media

comment:5 @alconebay3 years ago

Direction is normally what is used with image editing, not axis. "flip" and "flop" usage is backwards according to ImageMagick (http://www.imagemagick.org/script/convert.php):

-flip (flip image in the vertical direction)

-flop (flop image in the horizontal direction)

However, changing the description to axis would help those who have already put this method to use.

Version 0, edited 3 years ago by alconebay (next)

comment:6 @ryan3 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In 23750:

Clarify phpdoc for the vertical and horizontal arguments to the flip() method in WP_Image_Editor*.

Props dh-shredder
fixes #23775

Note: See TracTickets for help on using tickets.