Title: Error: Call to undefined method WP_Error::set_quality
Last modified: January 21, 2019

---

# Error: Call to undefined method WP_Error::set_quality

 *  [tbenyon](https://wordpress.org/support/users/tbenyon/)
 * (@tbenyon)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/error-call-to-undefined-method-wp_errorset_quality/)
 * Hey,
 * I’m getting the following error when I click the crop button.
 *     ```
       PHP Fatal error:  Uncaught Error: Call to undefined method WP_Error::set_quality() in /wp-content/plugins/acf-image-crop-add-on/acf-image-crop-v5.php:526
       Stack trace:
       #0 /wp-content/plugins/acf-image-crop-add-on/acf-image-crop-v5.php(502): acf_field_image_crop->generate_cropped_image('2756', '0', '1920', '221', '656', '1200', '270', true, 'medium')
       ...
         thrown in /Users/tom.benyon/Projects/WP_DEV_ENV/wp-content/plugins/acf-image-crop-add-on/acf-image-crop-v5.php on line 526
       ```
   
 * It’s referring to this code block and the last line here is throwing the error:
 *     ```
           function generate_cropped_image($id, $x1, $x2, $y1, $y2, $targetW, $targetH, $saveToMediaLibrary, $previewSize){//$id, $x1, $x2, $y$, $y2, $targetW, $targetH){
               require_once ABSPATH . "/wp-admin/includes/file.php";
               require_once ABSPATH . "/wp-admin/includes/image.php";
   
               // Create the variable that will hold the new image data
               $imageData = array();
   
               // Fetch media library info
               $mediaDir = wp_upload_dir();
   
               // Get original image info
               $originalImageData = wp_get_attachment_metadata($id);
   
               // Get image editor from original image path to crop the image
               $image = wp_get_image_editor( $mediaDir['basedir'] . '/' . $originalImageData['file'] );
   
               // Set quality
               $image->set_quality( apply_filters('acf-image-crop/image-quality', 100) );
       ```
   
 * This means your error handling that follows this line is not working.
 * Because of that the front end gets hung in a state where cancel and Crop buttons
   are deactivated as a 500 error is getting returned from the AJAX response.
 * The suggested code below fixes two issues. Firstly it ensure your error handling
   still triggers if the $image is not grabbed correctly. Secondly it fixes an issue
   for users like me who have their images stored on a CDN. The way you were grabbing
   the image didn’t cater for this.
 *     ```
           function generate_cropped_image($id, $x1, $x2, $y1, $y2, $targetW, $targetH, $saveToMediaLibrary, $previewSize){//$id, $x1, $x2, $y$, $y2, $targetW, $targetH){
               require_once ABSPATH . "/wp-admin/includes/file.php";
               require_once ABSPATH . "/wp-admin/includes/image.php";
   
               // Create the variable that will hold the new image data
               $imageData = array();
   
               // Fetch media library info
               $mediaDir = wp_upload_dir();
   
               // Get original image info
               $originalImageData = wp_get_attachment_metadata($id);
   
               // Get image editor from original image path to crop the image
               $image = wp_get_image_editor( wp_get_attachment_image_src($id)[0] );
   
               if (method_exists($image, 'set_quality')) {
                   // Set quality
                   $image->set_quality(apply_filters('acf-image-crop/image-quality', 100));
               } else {
                   $image = new WP_Error( '500', "Could not edit selected image. Does this image exist on the server?");
               } 
       ```
   
 * This does not fix everything but this was all the time I could justify investing
   in this.
 * The remaining issue is that although your code completes without error now, the
   image stored is simply a black rectangle.
 * For context I am using the AWS S3 Offload plugin for my image storage.
 * Thanks,
 * Tom

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [theheavenlyhash](https://wordpress.org/support/users/theheavenlyhash/)
 * (@theheavenlyhash)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/error-call-to-undefined-method-wp_errorset_quality/#post-11560839)
 * Hi tom i too am having this issue and am using an aws s3 offload plugin. Did 
   you get any futher as to avoid the black rectangle?
 *  Thread Starter [tbenyon](https://wordpress.org/support/users/tbenyon/)
 * (@tbenyon)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/error-call-to-undefined-method-wp_errorset_quality/#post-11573988)
 * Hey [@theheavenlyhash](https://wordpress.org/support/users/theheavenlyhash/),
 * Sadly I didn’t. I just haven’t been using the plugin.
 * If you get anywhere please let me know.
 * Tom

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Error: Call to undefined method WP_Error::set_quality’ is closed to new
replies.

 * ![](https://s.w.org/plugins/geopattern-icon/acf-image-crop-add-on_e1e1e1.svg)
 * [Advanced Custom Fields: Image Crop Add-on](https://wordpress.org/plugins/acf-image-crop-add-on/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/acf-image-crop-add-on/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/acf-image-crop-add-on/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-image-crop-add-on/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-image-crop-add-on/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-image-crop-add-on/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [tbenyon](https://wordpress.org/support/users/tbenyon/)
 * Last activity: [6 years, 10 months ago](https://wordpress.org/support/topic/error-call-to-undefined-method-wp_errorset_quality/#post-11573988)
 * Status: not resolved