WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 10 months ago

#40087 new enhancement

Add ability to filter Imagemagick processing options

Reported by: aesqe Owned by:
Milestone: Awaiting Review Priority: normal
Severity: trivial Version: 4.7.3
Component: Media Keywords: reporter-feedback
Focuses: Cc:
PR Number:

Description

Hi everyone :)

TLDR: I want to be able to control Imagemagick's sampling factor value for JPEG images.

I haven't been able to find any info on whether it's possible to change this value in Imagemagick's defaults, and there don't seem to be any usable filters or actions in WP_Image_Editor_Imagick class.

To be able to set the sampling factor, one needs access to the Imagemagick instance, which is a protected var in the editor class, I guess for a reason.

Options:

a) a new public WP_Image_Editor_Imagick method which would be able to call Imagemagick instance methods, made available via an add_action call
b) add something like the following code to the set_quality method:

if( defined("IMAGICK_SAMPLING_FACTOR") ) {
    $this->image->setImageProperty('jpeg:sampling-factor', IMAGICK_SAMPLING_FACTOR);
}

Any ideas?

Thanks!

Change History (3)

#1 @aesqe
3 years ago

  • Keywords dev-feedback added
  • Severity changed from normal to trivial

This ticket was mentioned in Slack in #core-media by mike. View the logs.


10 months ago

#3 @mikeschroder
10 months ago

  • Keywords reporter-feedback added; dev-feedback removed
  • Type changed from feature request to enhancement

Thanks so much for the report!

At the moment, the intended way to make this change is by extending the WP_Image_Editor_Imagick class, and adding (replacing if you want) the new class to the list of editors with the wp_image_editors filter.

It's built this way to abstract away the internals of each image editor, because a filter specifically for Imagick wouldn't apply to GD, for example.

Will that work for your use-case?

Note: See TracTickets for help on using tickets.