With WP 3.5, they updated the image resizing scripts with wp_get_image_editor.

Currently, in this standalone script that is accessed with Ajax, I have included wp-load.php so I can access all of the WP functions. Particularly, $wpdb;. In order to use the $wpdb functions, I had to declare global $wpdb; first.

I assumed I had to do the same for wp_get_image_editor, but there is no global variable to declare.

When using:

$image = wp_get_image_editor($current);

//if (!is_wp_error($image)) {
    $image->resize(100, 100, false); }

nothing happens, and if I remove the if statement, I get the error

PHP Fatal error: Call to undefined method WP_Error::resize()

Does anyone know how I can do this? Would it be smarter to install my own image-resizing scripts?

1 Answer
1

Turns out I’m just silly.

WP_Error was the undefined method, not resize. I was sending a bad image location through the resize function. How silly of me! It was working all along.

I’ve included this on top

$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-load.php' );

and this is my image resize function

$image = wp_get_image_editor($current);

    if (!is_wp_error($image)) {
        $image->resize(100, 100, false);
        $image->save($target);
        return "succ";
    } else return "error";

Leave a Reply

Your email address will not be published. Required fields are marked *