DivisionByZeroError (Ajax response)
-
When opening the crop thumbnail editor on a single media page (on backend),
the editor popup stays empty, the ajax request is responded with HTTP 500 and the server logs:
NOTICE: PHP message: PHP Fatal error: Uncaught DivisionByZeroError: Modulo by zero in /srv/www/web/app/plugins/crop-thumbnails/functions/editor.php
-
Hi strarsis,
thank you for your bug-report. It would be great if you can provide more information:- On the NOTICE-message should be a line-number be displayed. It would be great to have that line-number.
- What custom image-sizes do you have in your theme?
The problem is that one of you image sizes has a zero value in it and the plugin do not prove that correctly. PHP sends a notice wich is interfere with the normal page output, so the page do not get loaded.
A quick fix would be to disable notice-messages. This can be done by editing your wp-config.php and adding/changing
define( 'WP_DEBUG', false );
. But i do not recommend that on the long term.Some more information:
– Current WordPress (4.9.8) is used
– Current Gutenberg (4.2.0) is used on all pages.Detailed error log:
POST /wp/wp-admin/admin-ajax.php” 200
WARNING: [pool www] child 20 said into stderr: “NOTICE: PHP message: PHP Fatal error: Uncaught DivisionByZeroError: Modulo by zero in /srv/www/web/app/plugins/crop-thumbnails/functions/editor.php:258″
GET /wp/wp-admin/admin-ajax.php” 500
WARNING: [pool www] child 20 said into stderr: “Stack trace:”
WARNING: [pool www] child 20 said into stderr: “#0 /srv/www/web/app/plugins/crop-thumbnails/functions/editor.php(251): CropPostThumbnailsEditor::my_gcd(0, 0)”
WARNING: [pool www] child 20 said into stderr: “#1 /srv/www/web/app/plugins/crop-thumbnails/functions/editor.php(167): CropPostThumbnailsEditor->gcd(0, 0)”
WARNING: [pool www] child 20 said into stderr: “#2 /srv/www/web/app/plugins/crop-thumbnails/functions/editor.php(98): CropPostThumbnailsEditor->getUncroppedImageData(200, ‘full’)”
WARNING: [pool www] child 20 said into stderr: “#3 /srv/www/web/app/plugins/crop-thumbnails/functions/editor.php(20): CropPostThumbnailsEditor->getCropData()”
WARNING: [pool www] child 20 said into stderr: “#4 /srv/www/web/wp/wp-includes/class-wp-hook.php(286): CropPostThumbnailsEditor->provideCropData(”)”
WARNING: [pool www] child 20 said into stderr: “#5 /srv/www/web/wp/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(”, Array)”
WARNING: [pool www] child 20 said into stderr: “#6 /srv/www/web/wp/wp-includes/plugin.php(453): WP_Hook->do_action(Array)”
WARNING: [pool www] child 20 said into stderr: “#7 /srv/www/web/wp/wp-admin/admin-ajax.php(100): do_action(‘wp_ajax_cpt_cro…’)”
WARNING: [pool www] child 20 said into stderr: “#8 {main}”
WARNING: [pool www] child 20 said into stderr: ” thrown in /srv/www/web/app/plugins/crop…”
POST /wp/wp-admin/admin-ajax.php” 200
Also some image sizes have been changed (theme is in development), however, a 0 width or height hadn’t been used.
Ideally the Crop-Thumbnails plugin should use some check to prevent this kind of errors, even when there are image sizes with 0 width or height (but how can this happen, is WordPress not checking this?).
Edit: Apparently this issue only occurs with some of the images, the Crop-Thumbnails editor opens for other images actually.
The Regenerate Thumbnails plugin list these image sizes:
[OK]thumbnail: 150×150 pixels (cropped to fit) IMG-150×150.jpg
[OK]medium: 300×300 pixels (proportionally resized to fit inside dimensions) IMG-199×300.jpg
[OK]medium_large: 768×0 pixels (proportionally resized to fit inside dimensions) IMG-768×1156.jpg
[OK]large: 1024×1024 pixels (proportionally resized to fit inside dimensions) IMG-680×1024.jpg
[OK]ab-block-post-grid-landscape: 600×400 pixels (cropped to fit) IMG-600×400.jpg
[OK]ab-block-post-grid-square: 600×600 pixels (cropped to fit) IMG-600×600.jpg
[OK]portrait: 160×160 pixels (cropped to fit) IMG-160×160.jpg
[OK]portrait-320: 320×320 pixels (cropped to fit) IMG-320×320.jpg
[OK]portrait-400: 400×400 pixels (cropped to fit) IMG-400×400.jpg
[OK]portrait-480: 480×480 pixels (cropped to fit) IMG-480×480.jpg
[OK]portrait-80: 80×80 pixels (cropped to fit) IMG-80×80.jpg
I deleted an image with which the issue occured and re-uploaded it and got this error during upload:
Warning: getimagesize(/srv/www/web/app/uploads/2018/11/IMG.jpg): failed to open stream: No such file or directory in /srv/www/web/wp/wp-admin/includes/image.php on line 82
Call Stack
# Time Memory Function Location
1 0.0626 409816 {main}( ) …/async-upload.php:0
2 6.8496 5020224 media_handle_upload( ) …/async-upload.php:81
3 7.0349 5096840 wp_generate_attachment_metadata( ) …/media.php:384
4 7.0364 5097288 getimagesize ( ) …/image.php:82
215
Apparently the image metadata is corrupted during upload, some image meta data is misisng.
Edit: Apparently the JPEG image file was somehow corrupted or not fully compatible with PHP image functions. It can be still opened in Photoshop and IrfanView without any problems or warnings though.
Resaving the JPEG image as JPEG (e.g. progressive for ensuring a re-encoding) still resulted in an image that causes the issue. Only also resizing the JPEG image by some pixels and resaving it as JPEG fixed the issue (although it is not the same JPEG image anymore).Hi strarsis,
thank your for the data. As you are already noticed, the image seems to be buggy – wordpress/php cant correctly read the dimensions from the image. I also got that bug by myself sometimes – but did not get the notice cause i often only display errors (not in development though).Cropping on that image will not be possible – but it should also not break the code. I will make some adjustments to prevent the bug. But for now i recommend you renew the file via photoshop. Once wordpress/php can correct read the dimensions there should be no problem cropping the image.
- The topic ‘DivisionByZeroError (Ajax response)’ is closed to new replies.