• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / image_edit_apply_changes() – Performs group of changes on Editor specified.

You appear to be a bot. Output may be restricted

Description

Performs group of changes on Editor specified.

Usage

$WP_Image_Editor = image_edit_apply_changes( $image, $changes );

Parameters

$image
( WP_Image_Editor ) required – WP_Image_Editor instance.
$changes
( array ) required – Array of change operations.

Returns

WP_Image_Editor WP_Image_Editor instance with changes applied.

Source

File name: wordpress/wp-admin/includes/image-edit.php


Lines:

1 to 100 of 122
function image_edit_apply_changes( $image, $changes ) {
  if ( is_gd_image( $image ) ) {
    /* translators: 1: $image, 2: WP_Image_Editor */
    _deprecated_argument( image_edit_apply_changes, '3.5.0', sprintf( __( '%1$s needs to be a %2$s object.' ), '$image', 'WP_Image_Editor' ) );
  }

  if ( ! is_array( $changes ) ) {
    return $image;
  }

  // Expand change operations.
  foreach ( $changes as $key => $obj ) {
    if ( isset( $obj->r ) ) {
      $obj->type  = 'rotate';
      $obj->angle = $obj->r;
      unset( $obj->r );
    } elseif ( isset( $obj->f ) ) {
      $obj->type = 'flip';
      $obj->axis = $obj->f;
      unset( $obj->f );
    } elseif ( isset( $obj->c ) ) {
      $obj->type = 'crop';
      $obj->sel  = $obj->c;
      unset( $obj->c );
    }
    $changes[ $key ] = $obj;
  }

  // Combine operations.
  if ( count( $changes ) > 1 ) {
    $filtered = array( $changes[0] );
    for ( $i = 0, $j = 1, $c = count( $changes ); $j < $c; $j++ ) {
      $combined = false;
      if ( $filtered[ $i ]->type == $changes[ $j ]->type ) {
        switch ( $filtered[ $i ]->type ) {
          case 'rotate':
            $filtered[ $i ]->angle += $changes[ $j ]->angle;
            $combined               = true;
            break;
          case 'flip':
            $filtered[ $i ]->axis ^= $changes[ $j ]->axis;
            $combined              = true;
            break;
        }
      }
      if ( ! $combined ) {
        $filtered[ ++$i ] = $changes[ $j ];
      }
    }
    $changes = $filtered;
    unset( $filtered );
  }

  // Image resource before applying the changes.
  if ( $image instanceof WP_Image_Editor ) {

    
/**
 * Filters the WP_Image_Editor instance before applying changes to the image.
 *
 * @since 3.5.0
 *
 * @param WP_Image_Editor $image   WP_Image_Editor instance.
 * @param array           $changes Array of change operations.
 */
    $image = apply_filters( 'wp_image_editor_before_change', $image, $changes );
  } elseif ( is_gd_image( $image ) ) {

    
/**
 * Filters the GD image resource before applying changes to the image.
 *
 * @since 2.9.0
 * @deprecated 3.5.0 Use {@see 'wp_image_editor_before_change'} instead.
 *
 * @param resource|GdImage $image   GD image resource or GdImage instance.
 * @param array            $changes Array of change operations.
 */
    $image = apply_filters_deprecated( 'image_edit_before_change', array( $image, $changes ), '3.5.0', 'wp_image_editor_before_change' );
  }

  foreach ( $changes as $operation ) {
    switch ( $operation->type ) {
      case 'rotate':
        if ( 0 != $operation->angle ) {
          if ( $image instanceof WP_Image_Editor ) {
            $image->rotate( $operation->angle );
          } else {
            $image = _rotate_image_resource( $image, $operation->angle );
          }
        }
        break;
      case 'flip':
        if ( 0 != $operation->axis ) {
          if ( $image instanceof WP_Image_Editor ) {
            $image->flip( ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 );
          } else {
            $image = _flip_image_resource( $image, ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 );
          }
        }
[1] [2] Next »

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 9th December 2020

Primary Sidebar

Information

Function name: image_edit_apply_changes
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-admin/includes/image-edit.php
File ref: wp-admin/includes/image-edit.php
Deprecated?: No
API Letters: A,C,E,I

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites