Make WordPress Core

Opened 5 months ago

Last modified 5 months ago

#63764 assigned defect (bug)

ImageMagick writeImage() causes duplicate inotify events during thumbnail generation

Reported by: agiabanis's profile agiabanis Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.8.2
Component: Media Keywords: has-patch
Focuses: Cc:

Description

When WordPress generates image thumbnails using ImageMagick, the writeImage() method in wp-includes/class-wp-image-editor-imagick.php causes duplicate CLOSE_WRITE,CLOSE inotify events.
Steps to reproduce:

  1. Upload an image to WordPress
  2. Monitor inotify events: inotifywait -m -e close_write /wp-content/uploads/
  3. Observe duplicate events for each thumbnail

Expected behavior:
One CLOSE_WRITE,CLOSE event per thumbnail file

Actual behavior:
Two CLOSE_WRITE,CLOSE events per thumbnail file

Root cause:
The writeImage() method performs internal buffering that creates two file operations:

  1. Write data to buffer
  2. Flush buffer to file

Proposed fix:
Replace writeImage() with getImageBlob() + file_put_contents() for single operation.

Files affected:

  • wp-includes/class-wp-image-editor-imagick.php (line 976)

Attachments (1)

fix-imagick-duplicate-events.patch (1.7 KB) - added by agiabanis 5 months ago.

Download all attachments as: .zip

Change History (2)

This ticket was mentioned in PR #9342 on WordPress/wordpress-develop by @agiabanis.


5 months ago
#1

Fixes duplicate CLOSE_WRITE,CLOSE events during thumbnail generation by replacing ImageMagick's writeImage() method with a combination of getImageBlob() and file_put_contents() for single file operation.

This eliminates the internal buffering that causes two file operations:

  1. Write data to buffer
  2. Flush buffer to file

Benefits:

  • Eliminates duplicate inotify events
  • Reduces file I/O operations
  • Improves performance for thumbnail generation
  • Maintains full compatibility with all ImageMagick versions
Note: See TracTickets for help on using tickets.