From 1234567890abcdef1234567890abcdef12345678 Mon Sep 17 00:00:00 2001
From: Your Name <anastasisgiabanis@gmail.com>
Date: Mon, 28 Jul 2025 20:32:00 +0000
Subject: [PATCH] Fix: Replace writeImage() with getImageBlob() + file_put_contents() to prevent duplicate inotify events
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
Props: [agiabanis]
Fixes: #[63764]
---
wp-includes/class-wp-image-editor-imagick.php | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/wp-includes/class-wp-image-editor-imagick.php b/wp-includes/class-wp-image-editor-imagick.php
index abc1234..def5678 100644
|
a
|
b
|
private function write_image( $image, $filename ) { |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | try { |
| 975 | | return $image->writeImage( $filename ); |
| | 975 | $image_data = $image->getImageBlob(); |
| | 976 | if (file_put_contents($filename, $image_data) === false) { |
| | 977 | return new WP_Error( 'image_save_error', 'Failed to write image data to file', $filename ); |
| | 978 | } |
| | 979 | return true; |
| 976 | 980 | } catch ( Exception $e ) { |
| 977 | 981 | return new WP_Error( 'image_save_error', $e->getMessage(), $filename ); |
| 978 | 982 | } |