Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

BuddyPress Avatar Crop Conflict With Image Resizing Script WordPress

  • SOLVED

I'm using the following image resizing script: http://core.trac.wordpress.org/ticket/15311

However when trying to crop my avatar on the following BuddyPress page (http://ghostpool.com/wordpress/score/members/admin/profile/change-avatar), the images produce the following error:

Catchable fatal error: Object of class WP_Error could not be converted to string in /home/ghostpool/ghostpool.com/wordpress/score/wp-content/themes/score/lib/scripts/image-resizer.php on line 96

Line 96 is: $new_img_size = getimagesize( $new_img_path );

Answers (3)

2011-11-10

Francisco Javier Carazo Gil answers:

Try to see the error, in php.ini:


display_error = on

Reload your server and try again. You may see another message with more information.

As Luis says: $new_img_path in this moment is a WP_Error object so the error is previous, maybe in the line before, try to see the value of the four parameters:

$new_img_path = image_resize( $file_path, $width, $height, $crop );
$new_img_size = getimagesize( $new_img_path );


GhostPool comments:

The error is coming from:

$new_img_path = image_resize( $actual_file_path, $width, $height, $crop );

The error only occurs on the BuddyPress page where you crop your avatar, the image script works on every other page. I'm guessing there must be a conflict with the BP image cropper, but unsure how to tackle it.


Francisco Javier Carazo Gil comments:

It seems to be what you say. Maybe: $actual_file_path is not correct. You can debug it using, for example, JavaScript alerts.

Change:
$new_img_path = image_resize( $actual_file_path, $width, $height, $crop );

For this one:
echo "<script>alert('actual_file_path:$actual_file_path\n
width:$width\n
height:$heigh\n
crop:$crop')</script>"$new_img_path = image_resize( $actual_file_path, $width, $height, $crop );


When you will see the values, we can continue debugging.


Francisco Javier Carazo Gil comments:

I have an error writing, the second code is:

echo "<script>alert('actual_file_path:$actual_file_path\n
width:$width\n
height:$heigh\n
crop:$crop')</script>";

$new_img_path = image_resize( $actual_file_path, $width, $height, $crop );


Hope it helps!


GhostPool comments:

I added the alert code but it's not being loaded on the page with the error unfortunately.


Francisco Javier Carazo Gil comments:

See your JavaScript console. Maybe there will be any errors and you'll be able to see a string with the values.

In wp-config.php set:
define( 'WP_DEBUG', true );

Try now.


GhostPool comments:

Thanks I turned on define( 'WP_DEBUG', true ); but it didn't return any error. Checking the JavaScript console gives the alert message. Unfortunately it returns the correct information (image url, width, height and cropping) just like any other page. Any ideas?


Francisco Javier Carazo Gil comments:

If the values are OK the problem is in image_resize.

This function is defined in /wp-includes/media.php and it returns a WP_Error in this cases:

if ( IMAGETYPE_GIF == $orig_type ) {
if ( !imagegif( $newimage, $destfilename ) )
return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
} elseif ( IMAGETYPE_PNG == $orig_type ) {
if ( !imagepng( $newimage, $destfilename ) )
return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
} else {
// all other formats are converted to jpg
$destfilename = "{$dir}/{$name}-{$suffix}.jpg";
if ( !imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
}


See the kind of WP_Error and continue debugging.

2011-11-10

Luis Cordova answers:

the error is before that line because it is already an WP_Error

thing is deeper, try tracking it down before that

2011-11-10

Kannan C answers:

did you noticed and using the updated code given by that author for sub folder WP installs? here http://core.trac.wordpress.org/ticket/15311#comment:13