Skip to content

Update Resizer.php#117

Open
Sioweb wants to merge 1 commit intocontao:1.xfrom
Sioweb:1.x
Open

Update Resizer.php#117
Sioweb wants to merge 1 commit intocontao:1.xfrom
Sioweb:1.x

Conversation

@Sioweb
Copy link
Copy Markdown

@Sioweb Sioweb commented Mar 28, 2026

Prevent animated GIF endless loop (Error 502)

Our customer has multiple animated GIF in Backend. Those cause slowed down backend and 502 Errors. What i see in the logs:

  1. Imagine Library Limitation: The Imagine library cannot properly process animated GIFs
  2. Frame Loss: During resize/crop operations, all frames except the first are discarded
  3. Invalid Cache: The cached result was a corrupted/incomplete GIF
  4. Recursion on Load: Attempting to load these invalid cached images triggered repeated processing attempts

Causing:

  1. 502 Bad Gateway errors when opening GIF files in Contao backend
  2. PHP memory limit or execution timeout due to deep recursion
  3. Custom server logs show repetitive processResize calls for the same file (Parent function was never called)

So i've made a little check to skip animated gifs.

Prevent animated GIF endless loop (Error 502)
@fritzmg
Copy link
Copy Markdown

fritzmg commented Mar 28, 2026

Frame Loss: During resize/crop operations, all frames except the first are discarded

In Contao, you need to set the following in order for Imagine to resize all frames:

# config/config.yaml
contao:
    image:
        imagine_options:
            flatten: false

@fritzmg
Copy link
Copy Markdown

fritzmg commented Mar 28, 2026

Invalid Cache: The cached result was a corrupted/incomplete GIF

We don't experience that on our sites. Can you post the GIF that caused it, plus your image size settings?

@ausi
Copy link
Copy Markdown
Member

ausi commented Mar 31, 2026

  1. The Imagine library cannot properly process animated GIFs

Which driver are you using? GD, IMagick or GMagick? (You can see that in the Contao tab of the debug toolbar)

3. Invalid Cache: The cached result was a corrupted/incomplete GIF

Can you provide such a corrupted file? As the resizer uses atomic write operations, this should never happen.

image/src/Resizer.php

Lines 216 to 217 in 06cafbc

// Atomic write operation
$this->filesystem->rename($tmpPath2, $path, true);


While I was not able to reproduce any recursions or other failures, I noticed that resizing an animated GIF takes a long time even if only the first frame is used in the resized result. We should check if we can improve perfomance by only loading the first frame for cases with flatten: true, that should be way faster then.

Should we add an image size option or a global option to skip resizing animated GIFs entirely?

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

Successfully merging this pull request may close these issues.

3 participants