Make WordPress Core

Ticket #45982: image-library-load-filters.diff

File image-library-load-filters.diff, 2.0 KB (added by joostdekeijzer, 6 years ago)

Hi, I have the same issue. The workaround from #39216 does not work for me, I need to setImageAlphaChannel. I'm using PHP7.2 with ImageMagick 6.9.10 and ghostscript 9.5. I've attached a patch that adds filters to both the Imagick class and the GD class both passing the $this->image object as a reference. Then, in a plugin, you can make the fix that works for you. Would that be a solution?

  • public_html/wp-includes/class-wp-image-editor-gd.php

    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 b class WP_Image_Editor_GD extends WP_Image_Editor { 
    112112                $this->update_size( $size[0], $size[1] );
    113113                $this->mime_type = $size['mime'];
    114114
     115                do_action_ref_array( 'gd_load', array( &$this->image, $filename, $this->mime_type ) );
     116
    115117                return $this->set_quality();
    116118        }
    117119
  • public_html/wp-includes/class-wp-image-editor-imagick.php

    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 b class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    146146                                $filename = $this->pdf_setup();
    147147                        }
    148148
     149                        do_action_ref_array( 'imagick_load_before_read', array( &$this->image, $filename, $file_extension ) );
     150
    149151                        // Reading image after Imagick instantiation because `setResolution`
    150152                        // only applies correctly before the image is read.
    151153                        $this->image->readImage( $filename );
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    160162                        }
    161163
    162164                        $this->mime_type = $this->get_mime_type( $this->image->getImageFormat() );
     165
     166                        do_action_ref_array( 'imagick_load_after_read', array( &$this->image, $filename, $file_extension, $this->mime_type ) );
    163167                } catch ( Exception $e ) {
    164168                        return new WP_Error( 'invalid_image', $e->getMessage(), $this->file );
    165169                }