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?

  • 2
    Why not use WordPress' built-in AJAX functionality? – Joseph Leedy Jan 28 '13 at 1:55
  • I'm using FineUploader to upload the images, and it uses the ajax, but it is a very complex plugin. I don't know how to convert it to Wordpress's built in ajax. – Jacob Raccuia Jan 28 '13 at 1:59
  • WordPress also has a built-in image uploader (based on PLUpload). – Joseph Leedy Jan 28 '13 at 14:05
  • I know! I first tried to modify their image uploader, but it proved very difficult. I needed to upload images and send them to select locations in the uploads folder, based on the user settings. – Jacob Raccuia Jan 28 '13 at 22:23

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);
        return "succ";
    } else return "error";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.