wp_get_image_editor example

/* * If the file doesn't exist, attempt a URL fopen on the src link. * This can occur with certain file replication plugins. * Keep the original file path to get a modified name later. */
        $image_file_to_edit = $image_file;
        if ( ! file_exists( $image_file_to_edit ) ) {
            $image_file_to_edit = _load_image_to_edit_path( $attachment_id );
        }

        $image_editor = wp_get_image_editor( $image_file_to_edit );

        if ( is_wp_error( $image_editor ) ) {
            return new WP_Error(
                'rest_unknown_image_file_type',
                __( 'Unable to edit this image.' ),
                array( 'status' => 500 )
            );
        }

        foreach ( $modifiers as $modifier ) {
            $args = $modifier['args'];
            

function image_resize( $file$max_w$max_h$crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
    _deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' );

    $editor = wp_get_image_editor( $file );
    if ( is_wp_error( $editor ) )
        return $editor;
    $editor->set_quality( $jpeg_quality );

    $resized = $editor->resize( $max_w$max_h$crop );
    if ( is_wp_error( $resized ) )
        return $resized;

    $dest_file = $editor->generate_filename( $suffix$dest_path );
    $saved = $editor->save( $dest_file );

    
if ( ! file_exists( $src_file ) ) {
            /* * If the file doesn't exist, attempt a URL fopen on the src link. * This can occur with certain file replication plugins. */
            $src = _load_image_to_edit_path( $src, 'full' );
        } else {
            $src = $src_file;
        }
    }

    $editor = wp_get_image_editor( $src );
    if ( is_wp_error( $editor ) ) {
        return $editor;
    }

    $src = $editor->crop( $src_x$src_y$src_w$src_h$dst_w$dst_h$src_abs );
    if ( is_wp_error( $src ) ) {
        return $src;
    }

    if ( ! $dst_file ) {
        $dst_file = str_replace( wp_basename( $src_file ), 'cropped-' . wp_basename( $src_file )$src_file );
    }

function image_make_intermediate_size( $file$width$height$crop = false ) {
    if ( $width || $height ) {
        $editor = wp_get_image_editor( $file );

        if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width$height$crop ) ) ) {
            return false;
        }

        $resized_file = $editor->save();

        if ( ! is_wp_error( $resized_file ) && $resized_file ) {
            unset( $resized_file['path'] );
            return $resized_file;
        }
    }

function stream_preview_image( $post_id ) {
    $post = get_post( $post_id );

    wp_raise_memory_limit( 'admin' );

    $img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) );

    if ( is_wp_error( $img ) ) {
        return false;
    }

    $changes = ! empty( $_REQUEST['history'] ) ? json_decode( wp_unslash( $_REQUEST['history'] ) ) : null;
    if ( $changes ) {
        $img = image_edit_apply_changes( $img$changes );
    }

    // Scale the image.
Home | Imprint | This part of the site doesn't use cookies.