Large GIFs as inline images can take minutes to load the page due to getWidth coalesce

Created on 19 December 2024, 4 months ago

Problem/Motivation

When using 10.3, CKEditor5 and using the upload inline image toolbar option, you can upload an extremely large, for example 50MB, GIF animation. Subsequent viewing of the page can take a long time and timeout as the editor rendering (core/modules/editor/src/Plugin/Filter/EditorFileReference) calls getWidth and getHeight - and this causes the coalesce of the images which uses a huge amount of memory and time depending on the GIF.

Steps to reproduce

Drupal 10.3
CKEditor
Upload Image button
Create new node
Add a GIF image >50MB with many frames >100 frames
Attempt to view the node

It seems that getWidth and getHeight are triggering Imagick to both load the full image, loading megabytes of data, and also causing Imagick to coalesce the images. The load itself for me can take 20 seconds alone, and then the coalescing takes minutes.

Proposed resolution

GD toolkit uses getimagesize and does not load the image until the resource is asked for.
I would propose something along the lines of:
- If GD is installed - when parseFile is called - simply use GD to load the image data as this is massively optimised, taking 4ms in my case to identify the GIF width and height - compared to 20 seconds for IMagick to not have any width/height and the coalesce minutes to generate it. Store this.
- Parse the image during getResource only - so only parse it when operations take place

This will let getWidth and getHeight just use the getimagesize data from parseFile if the image isn't loaded - if it's loaded then perhaps coalesce at that point as things could have been changed

WDYT?

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom Driskell

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024