From 444dd654a002a57248b6cd8ac4a7ecd90dea4dcb Mon Sep 17 00:00:00 2001
From: joostdekeijzer <j@dkzr.nl>
Date: Mon, 18 Nov 2019 17:26:09 +0100
Subject: [PATCH] add filters to gd and imagick load method

---
 public_html/wp-includes/class-wp-image-editor-gd.php      | 2 ++
 public_html/wp-includes/class-wp-image-editor-imagick.php | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/public_html/wp-includes/class-wp-image-editor-gd.php b/public_html/wp-includes/class-wp-image-editor-gd.php
index 53cf2ef9..13f05cda 100644
--- a/public_html/wp-includes/class-wp-image-editor-gd.php
+++ b/public_html/wp-includes/class-wp-image-editor-gd.php
@@ -112,6 +112,8 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
 		$this->update_size( $size[0], $size[1] );
 		$this->mime_type = $size['mime'];
 
+		do_action_ref_array( 'gd_load', array( &$this->image, $filename, $this->mime_type ) );
+
 		return $this->set_quality();
 	}
 
diff --git a/public_html/wp-includes/class-wp-image-editor-imagick.php b/public_html/wp-includes/class-wp-image-editor-imagick.php
index c014696b..e07c14a2 100644
--- a/public_html/wp-includes/class-wp-image-editor-imagick.php
+++ b/public_html/wp-includes/class-wp-image-editor-imagick.php
@@ -146,6 +146,8 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
 				$filename = $this->pdf_setup();
 			}
 
+			do_action_ref_array( 'imagick_load_before_read', array( &$this->image, $filename, $file_extension ) );
+
 			// Reading image after Imagick instantiation because `setResolution`
 			// only applies correctly before the image is read.
 			$this->image->readImage( $filename );
@@ -160,6 +162,8 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
 			}
 
 			$this->mime_type = $this->get_mime_type( $this->image->getImageFormat() );
+
+			do_action_ref_array( 'imagick_load_after_read', array( &$this->image, $filename, $file_extension, $this->mime_type ) );
 		} catch ( Exception $e ) {
 			return new WP_Error( 'invalid_image', $e->getMessage(), $this->file );
 		}
-- 
2.24.0

