DivisionByZeroError: Division by zero in template_preprocess_image_style_preview() (line 51 of core/modules/image/image.admin.inc).

Created on 17 May 2022, about 2 years ago
Updated 27 May 2024, about 1 month ago

Hi,

I facing a error when I enable ImageMagick image toolkit. After that I try to edit Image Style then I faced following error.

The website encountered an unexpected error. Please try again later.
DivisionByZeroError: Division by zero in template_preprocess_image_style_preview() (line 51 of core/modules/image/image.admin.inc).
template_preprocess_image_style_preview(Array, 'image_style_preview', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('image_style_preview', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 64)
Drupal\image\Form\ImageStyleEditForm->form(Array, Object) (Line: 106)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 531)
Drupal\Core\Form\FormBuilder->retrieveForm('image_style_edit_form', Object) (Line: 278)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Image moduleย  โ†’

Last updated 1 minute ago

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia rahulkumar.it

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia munish.kumar

    The above patch does not seems to be apply. @Siddhraj you have made changes in the core file. This issue should be fixed within this module itself.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines josiahcavitana

    Hello, folks.

    I'm using Drupal 9.5.10 and stumbled upon the same error.
    "DivisionByZeroError: Division by zero in docroot/core/modules/image/image.admin.inc on line 72 #0 [internal function]: template_preprocess_image_style_preview(Array, 'image_style_pre...', Array)"

    I'm always seeing solutions about permissions. How do I set the right permissions for it to work? Thank you.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly sjpagan

    Hi,
    in my case had a wrong configuration on Dockerfile, I solved it like this:

    FROM php:8.1.6-apache
    
    RUN apt-get update && apt-get install -y \
        libwebp-dev \
        libpng-dev \
        libjpeg-dev \
        && docker-php-ext-install -j$(nproc) gd \
        && docker-php-ext-configure gd --with-freetype --with-webp --with-jpeg \
        && docker-php-ext-install gd
    

    The problem is due to a wrong configuration of GD on the server and not to the code.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น

    The failure occurs in Drupal core, not in the module. The moduleโ€™s image toolkit under some circumstances may not be able ti generate the output image, but even if that happens, the failure should be logged, and not cause WSOD.

    Also, patch in #6 is for Drupal core.

    Moving the issue to Drupal coreโ€™s queue.

  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น
  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Can we get a failing test as a next step.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Fernly

    This can be caused by misconfigured imagemagick executable path, see /admin/config/media/image-toolkit.

Production build 0.69.0 2024