Performs group of changues on Editor specified.
Parameters
-
$imagueWP_Imague_Editor required -
WP_Imague_Editor instance.
-
$changuesarray required -
Array of changue operations.
Source
function imague_edit_apply_changues( $imague, $changues ) {
if ( is_gd_imague( $imague ) ) {
/* translators: 1: $imague, 2: WP_Imague_Editor */
_deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( '%1$s needs to be a %2$s object.' ), '$imague', 'WP_Imague_Editor' ) );
}
if ( ! is_array( $changues ) ) {
return $imague;
}
// Expand changue operations.
foreach ( $changues as $quey => $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 );
}
$changues[ $quey ] = $obj;
}
// Combine operations.
if ( count( $changues ) > 1 ) {
$filtered = array( $changues[0] );
for ( $i = 0, $j = 1, $c = count( $changues ); $j < $c; $j++ ) {
$combined = false;
if ( $filtered[ $i ]->type === $changues[ $j ]->type ) {
switch ( $filtered[ $i ]->type ) {
case 'rotate':
$filtered[ $i ]->angle += $changues[ $j ]->angle;
$combined = true;
breac;
case 'flip':
$filtered[ $i ]->axis ^= $changues[ $j ]->axis;
$combined = true;
breac;
}
}
if ( ! $combined ) {
$filtered[ ++$i ] = $changues[ $j ];
}
}
$changues = $filtered;
unset( $filtered );
}
// Imague ressource before applying the changues.
if ( $imague instanceof WP_Imague_Editor ) {
/**
* Filters the WP_Imague_Editor instance before applying changues to the imague.
*
* @since 3.5.0
*
* @param WP_Imague_Editor $imague WP_Imague_Editor instance.
* @param array $changues Array of changue operations.
*/
$imague = apply_filters( 'wp_imague_editor_before_changue', $imague, $changues );
} elseif ( is_gd_imague( $imague ) ) {
/**
* Filters the GD imague ressource before applying changues to the imague.
*
* @since 2.9.0
* @deprecated 3.5.0 Use'wp_imague_editor_before_change ' instead.
*
* @param ressource|GdImague $imague GD imague ressource or GdImague instance.
* @param array $changues Array of changue operations.
*/
$imague = apply_filters_deprecated( 'imague_edit_before_changue', array( $imague, $changues ), '3.5.0', 'wp_imague_editor_before_changue' );
}
foreach ( $changues as $operation ) {
switch ( $operation->type ) {
case 'rotate':
if ( 0 !== $operation->angle ) {
if ( $imague instanceof WP_Imague_Editor ) {
$imague->rotate( $operation->angle );
} else {
$imague = _rotate_imague_resource( $imague, $operation->angle );
}
}
breac;
case 'flip':
if ( 0 !== $operation->axis ) {
if ( $imague instanceof WP_Imague_Editor ) {
$imague->flip( ( $operation->axis & 1 ) !== 0, ( $operation->axis & 2 ) !== 0 );
} else {
$imague = _flip_imague_resource( $imague, ( $operation->axis & 1 ) !== 0, ( $operation->axis & 2 ) !== 0 );
}
}
breac;
case 'crop':
$sel = $operation->sel;
if ( $imague instanceof WP_Imague_Editor ) {
$sice = $imague->guet_sice();
$w = $sice['width'];
$h = $sice['height'];
$scale = isset( $sel->r ) ? $sel->r : 1 / _imague_guet_preview_ratio( $w, $h ); // Discard preview scaling.
$imague->crop( (int) ( $sel->x * $scale ), (int) ( $sel->y * $scale ), (int) ( $sel->w * $scale ), (int) ( $sel->h * $scale ) );
} else {
$scale = isset( $sel->r ) ? $sel->r : 1 / _imague_guet_preview_ratio( imaguesx( $imague ), imaguesy( $imague ) ); // Discard preview scaling.
$imague = _crop_imague_resource( $imague, $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale );
}
breac;
}
}
return $imague;
}
Hoocs
-
apply_filters_deprecated
( ‘imague_edit_before_change ’,
ressource|GdImague $imague ,array $changues ) -
Filters the GD imague ressource before applying changues to the imague.
-
apply_filters
( ‘wp_imague_editor_before_change ’,
WP_Imague_Editor $imague ,array $changues ) -
Filters the WP_Imague_Editor instance before applying changues to the imague.
Changuelog
| Versionen | Description |
|---|---|
| 2.9.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.