Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
1  
Why not use WordPress' built-in AJAX functionality? –  Joseph 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 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
add comment

1 Answer 1

up vote 0 down vote accepted

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";
share|improve this answer
1  
Please accept your own answer –  Pieter Goosen Apr 6 at 8:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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