Opened 12 months ago
Last modified 4 weeks ago
#63764 assigned defect (bug)
ImageMagick writeImage() causes duplicate inotify events during thumbnail generation
| Reported by: | agiabanis | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Media | Version: | 6.8.2 |
| Severity: | normal | Keywords: | has-patch reporter-feedback |
| Cc: | Focuses: |
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:
- Upload an image to WordPress
- Monitor inotify events:
inotifywait -m -e close_write /wp-content/uploads/ - 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:
- Write data to buffer
- 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)
Change History (3)
This ticket was mentioned in PR #9342 on WordPress/wordpress-develop by @agiabanis.
12 months ago
#1
#2
@
4 weeks ago
- Keywords reporter-feedback added
I cant replicate this. First, inotifywait -m -e close_write /wp-content/uploads doesnt show anything at all. But if I navigate to wp-content/uploads/2026/06 and run inotifywait -m -e close_write . it shows this
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-scaled.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-300x200.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-1024x683.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-150x150.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-768x512.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-1536x1024.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-2048x1365.jpg
./ CLOSE_WRITE,CLOSE pexels-adi-k-182036-28909955-1-624x416.jpg
I suspect this is a server/OS issue... Can you share details about your environment? Site Health has lots to share: https://[YOURSITE.COM]/wp-admin/site-health.php
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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:
Benefits: