WP_get_image_editor resizing images in a foreach loop

I am generating avatars from an image file upload. When running the function, WordPress does create the first image image-32×32.gif but fails on the remainder of the loop. I suspect it’s due to concurrency.

public function process_uploaded_file($file)
{
$editor = wp_get_image_editor($file);
$sizes = [32, 64, 128, 256, 512];
foreach ($sizes as $size) {
$result = $editor->resize($size, $size, true); //LINE 217
if (!is_wp_error($result)) {
$editor->save($editor->generate_filename());
}
}
}

What am I doing wrong?

Fatal error: Uncaught Error: Call to undefined method WP_Error::resize() in /Users/…/class-gf-avatar-field.php on line 217
( ! ) Error: Call to undefined method WP_Error::resize() in /…/class-gf-avatar-field.php on line 217

Read more here:: WP_get_image_editor resizing images in a foreach loop

Leave a Reply

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