The image_edit_apply_changes() WordPress PHP function performs a group of changes on a specified WP_Image_Editor instance.
Usage
image_edit_apply_changes( $image, $changes );
Example:
// Create a WP_Image_Editor instance for an image
$image = wp_get_image_editor( 'path/to/image.jpg' );
// Define an array of changes to apply
$changes = array(
array( 'r' => 90 ),
array( 'f' => 'horizontal' )
);
// Apply the changes
image_edit_apply_changes( $image, $changes );
Parameters
$image(WP_Image_Editor) – The WP_Image_Editor instance to apply changes to.$changes(array) – An array of change operations to apply.
More information
See WordPress Developer Resources: image_edit_apply_changes
Examples
Rotating an image
Rotating an image by 90 degrees.
$image = wp_get_image_editor( 'path/to/image.jpg' ); $changes = array( array( 'r' => 90 ) ); image_edit_apply_changes( $image, $changes );
Flipping an image horizontally
Flipping an image horizontally.
$image = wp_get_image_editor( 'path/to/image.jpg' ); $changes = array( array( 'f' => 'horizontal' ) ); image_edit_apply_changes( $image, $changes );
Flipping an image vertically
Flipping an image vertically.
$image = wp_get_image_editor( 'path/to/image.jpg' ); $changes = array( array( 'f' => 'vertical' ) ); image_edit_apply_changes( $image, $changes );
Rotating and flipping an image
Rotating an image by 180 degrees and flipping it horizontally.
$image = wp_get_image_editor( 'path/to/image.jpg' );
$changes = array(
array( 'r' => 180 ),
array( 'f' => 'horizontal' )
);
image_edit_apply_changes( $image, $changes );
Applying multiple changes at once
Rotating an image by 270 degrees, flipping it horizontally, and then flipping it vertically.
$image = wp_get_image_editor( 'path/to/image.jpg' );
$changes = array(
array( 'r' => 270 ),
array( 'f' => 'horizontal' ),
array( 'f' => 'vertical' )
);
image_edit_apply_changes( $image, $changes );