0

Trying to debug the situation. Getting close, but will need a little help!!

Here is the error:

Catchable fatal error: Object of class WP_Error could not be converted to string in /home/website/public_html/wp-content/themes/Alexia/lib/functions/common.php on line 97

And my code from the error:

// no cache files - let's finally resize it
        $new_img_path = image_resize( $file_path, $width, $height, $crop );
line 97-->      $new_img_size = getimagesize( $new_img_path );
        $new_img = str_replace( basename( $image_src[0] ), basename( $new_img_path ), $image_src[0] );
        // resized output
        $vt_image = array (
            'url' => $new_img,
            'width' => $new_img_size[0],
            'height' => $new_img_size[1]
        );

        return $vt_image;
    }

    // default output - without resizing

Thanks in advance NINJAS!!

4
  • The function image_resize has been deprecated in favor of WP_Image_Editor
    – birgire
    Commented Aug 7, 2013 at 14:18
  • 1
    ps: image_resize returns WP_Error on failure so you are most likely trying to feed getimagesize() with the WP_Error object instead of a string input value as expected. Do some error checks before using it.
    – birgire
    Commented Aug 7, 2013 at 14:23
  • @birgire please post answers as answers, rather than as comments. Commented Aug 7, 2013 at 16:06
  • @ChipBennett, thanks : my comment didn't start out as an answer but after few thoughts and edits, it became a "comment-answer", and 1 minute later, very similar answer was posted ;-)
    – birgire
    Commented Aug 7, 2013 at 16:25

1 Answer 1

3

image_resize (deprecated) is returning an error object so really, the problem is here: $new_img_path = image_resize( $file_path, $width, $height, $crop ); Something is wrong with that line and you are not checking whether the return value is an error object or a string before trying to use the return value as a string.

You did not post any code that might help me work out what is wrong with $new_img_path = image_resize( $file_path, $width, $height, $crop ); but at the very least you should do:

$new_img_path = image_resize( $file_path, $width, $height, $crop );
if( !is_wp_error()) {
    $new_img_size = getimagesize( $new_img_path );
    // ...

Converting to use WP_Image_Editor would be wiser though.

4
  • ok, so I can convert it using wp_image_editor ?
    – eberswine
    Commented Aug 7, 2013 at 16:04
  • Yess, you can and should convert to WP_Image_Editor Deprecated functions will eventually go away.
    – s_ha_dum
    Commented Aug 7, 2013 at 16:25
  • Any chance someone could help converting ?
    – eberswine
    Commented Aug 7, 2013 at 16:32
  • I can probably work it out later
    – s_ha_dum
    Commented Aug 7, 2013 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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