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

Created on 17 May 2022, over 2 years ago
Updated 18 January 2023, almost 2 years 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

Active

Version

3.0

Component
Image moduleย  โ†’

Last updated 1 day ago

Created by

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

Live updates comments and jobs are added and updated live.
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 almost 2 years 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 almost 2 years 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 12 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น
  • Status changed to Needs work 12 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.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mark_fullmer Tucson

    I can confirm that the answer in #11 worked for me -- it was resolvable by configuring the GD toolkit "correctly".

  • ๐Ÿ‡ช๐Ÿ‡ธSpain manuel garcia

    Also ran into this today - in my case setting proper permissions on the files folder did the trick as well, so thank you @zigazou for sharing.

Production build 0.71.5 2024