Skip to content

GD: Use imageflip() for flipping images - #13549

Closed
arshidkv12 wants to merge 5 commits into
WordPress:trunkfrom
arshidkv12:gd-1
Closed

arshidkv12 wants to merge 5 commits into
WordPress:trunkfrom
arshidkv12:gd-1

Conversation

@arshidkv12

Copy link
Copy Markdown

Use imageflip() in WP_Image_Editor_GD::flip() instead of imagecopyresampled() with negative dimensions.

This fixes image flipping with PHP 8.6 / GD 2.4.0, where the existing implementation can produce incorrect pixel data.

Trac ticket: https://core.trac.wordpress.org/ticket/66113

Use of AI Tools

AI assistance: Yes
Tool(s): ChatGPT
Model(s): GPT-5.6 Luna
Used for: Debugging and test suggestions;

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props arshidkv12, dhruvang21.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@dhruvang21 dhruvang21 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The move from imagecopyresampled() to imageflip() otherwise looks good.

* @param bool $horz Flip along Horizontal Axis.
* @param bool $vert Flip along Vertical Axis.
* @return true|WP_Error
* @return bool|WP_Error

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we preserve the true|WP_Error return contract here?

imageflip() returns bool, so returning it directly means this method can now return false when the GD operation fails. The parent WP_Image_Editor::flip() contract is true|WP_Error, and the Imagick implementation also converts failures to WP_Error.

I think we should keep @return true|WP_Error and convert a false result from imageflip() into the existing image_flip_error WP_Error, e.g.:

$result = imageflip( ... );

if ( $result ) {
	return true;
}

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

@desrosj

desrosj commented Nov 3, 2026

Copy link
Copy Markdown
Member

Hi @arshidkv12,

Thank you for opening this PR and contributing to WordPress! ❤️

It seems that there is still unaddressed feedback on here, and #13920 and #13925 are much further along as they have unit tests and documentation about the broader consequences and edge cases from switching to using imageflip().

I'm going to close this out so that efforts can be focused in one place, but please do feel free to continue helping to fix this.

@desrosj desrosj closed this Nov 3, 2026
@arshidkv12

Copy link
Copy Markdown
Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants