Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Call to undefined method WP_Image_Editor_GD::get_error_message() #1908

Closed
ob-ivan opened this issue Mar 21, 2018 · 8 comments
Closed
Assignees
Milestone

Comments

@ob-ivan
Copy link
Contributor

ob-ivan commented Mar 21, 2018

WordPress version: 4.9.4
AMP for WP version: 0.9.84.1

In our setup, development machines mount images folder from production with readonly permission level.

When the plugin tries to resize a picture on a development machine, it results in a Fatal error, the log follows.

PHP Fatal error:  Uncaught Error: Call to undefined method WP_Image_Editor_GD::get_error_message() in /path/to/public_html/wp-content/plugins/accelerated-mobile-pages/includes/vendor/aq_resizer.php:162
Stack trace:
#0 /path/to/public_html/wp-content/plugins/accelerated-mobile-pages/includes/vendor/aq_resizer.php(263): Aq_Resize->process('https://www.slr...', 100, 75, true, false, true)
#1 /path/to/public_html/wp-content/plugins/accelerated-mobile-pages/components/loop/loop.php(316): ampforwp_aq_resize('https://www.slr...', 100, 75, true, false, true)
#2 /path/to/public_html/wp-content/plugins/accelerated-mobile-pages/templates/design-manager/design-1/index.php(91): amp_loop_image(Array)
#3 /path/to/public_html/wp-content/plugins/accelerated-mobile-pages/includes/vendor/amp/includes/class-amp-post-template.php(433): include('/home/web/smith...')
#4 /path/to/public_html/wp-content/plugins/accelerated-mobile-pages/includes/vendor/amp/includes/clas in /path/to/public_html/wp-content/plugins/accelerated-mobile-pages/includes/vendor/aq_resizer.php on line 162

As far as I recognize, there is a typo in aq_resizer.php on line 162. Instead of:

$editor->get_error_message()

it should read:

$resized_file->get_error_message()
@ob-ivan
Copy link
Contributor Author

ob-ivan commented Mar 21, 2018

It would also be nice to have some sort of control over how I'd like to handle this situation. While in some cases a warning is a perfectly valid response ("hey admin! shit happened with your file system! take some action NOW"), in this particular case I'd be happy to suppress the warning completely and return either the original image or some stub instead.

Even better if I could disable the resizing with a hook, something like:

add_filter('ampforwp_should_resize_pictures', function ($shouldResize) {
    // No resizing in debug mode, the readonly FS is by design.
    return !DEBUG_MODE && $shouldResize;
});

@ahmedkaludi
Copy link
Owner

@MARQAS @ajeetku

What are your thoughts?

@ahmedkaludi
Copy link
Owner

@ob-ivan So your image folder is read-only?
@ajeetku do you think it could be due to the $resized_file->get_error_message() as he mentioned?

@MARQAS
Copy link
Contributor

MARQAS commented Mar 21, 2018

@ob-ivan Have you tried changing the code as you suggested?

@ob-ivan
Copy link
Contributor Author

ob-ivan commented Mar 21, 2018

@ahmedkaludi Yes, the folder is read-only in some environments, while it is read-write in production environment.

@MARQAS Yes, I did that, and the fatal error goes away, but a warning remains:

PHP Warning:  imagejpeg(/path/to/public_html/system/samoe-dorogoe-elitnoe-zhile-v-mire-100x75.jpg): failed to open stream: Read-only file system in /path/to/public_html/wp-includes/class-wp-image-editor.php on line 402
Aq_Resize.process() error: Unable to save resized image file: \xd0\x9d\xd0\xb5 \xd1\x83\xd0\xb4\xd0\xb0\xd0\xbb\xd0\xbe\xd1\x81\xd1\x8c \xd1\x81\xd0\xbe\xd1\x85\xd1\x80\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x82\xd1\x8c \xd0\xb8\xd0\xb7\xd0\xbe\xd0\xb1\xd1\x80\xd0\xb0\xd0\xb6\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5

The problem with the warning is that it gets printed in html, and it looks awful: https://www.dropbox.com/s/72a7txwqk1bjjck/Screenshot%202018-03-21%2016.48.43.png?dl=0

I'm sorry to have confused you. My comment about the warning was a feature request, and I should have created a separate issue for that.

@MARQAS
Copy link
Contributor

MARQAS commented Mar 21, 2018

@ob-ivan Can you share your staging site with the same setup? So we can go deep into it?

We haven't written the whole code of aq_resizer, just made some modifications in it. So have to check the code for your use case.

I hope you can understand.

@ob-ivan
Copy link
Contributor Author

ob-ivan commented Mar 21, 2018

@MARQAS While as a fellow developer I understand the suggestion, I'm not allowed to. My employer is very strict about this. And I don't have a WordPress installation to experiment with on my private servers either :(

I believe you can reproduce the issue by temporarily revoking write permissions from the web server user (that is, unless you run apache/nginx from the same user you modify the code with).

Then go to wp-admin > AMP Settings > Design > HomePage > Override Homepage Thumbnail Size > Enable, and insert non-standard image sizes.

As soon as you request an archive page, a call to amp_loop_image function invoked forcefully with 'image_crop'=>'true' argument will eventually fall through to ampforwp_aq_resize call in components/loop/loop.php file.

Generally, my problem could be solved by providing a filter for $image_args variable in design-*/archive.php. I would remove the image_crop argument, add layout = responsible, and go happy with it.

So maybe it is easier to go that way?

PS. Still the reason for the fatal error is clearly an obvious typo in Aq_Resizer. I'll attach a PR shortly.

PPS. Hey, someone's already created one for the original repo: syamilmj/Aqua-Resizer#88 but it seems unsupported now.

ob-ivan pushed a commit to ob-ivan/accelerated-mobile-pages that referenced this issue Mar 21, 2018
MohammedKaludi added a commit that referenced this issue May 3, 2018
Fix the variable containing WP_Error to avoid a fatal (#1908)
@ahmedkaludi ahmedkaludi added this to the W15 milestone Jun 24, 2018
@ahmedkaludi ahmedkaludi modified the milestone: W15 Jun 25, 2018
@Sejiro-Hiko
Copy link
Contributor

@ob-ivan your pull request has been merged and all the issues related to the aq_resizer are resolved so I'm closing this ticket and if there's anything left out please create a new ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants