#38594 closed enhancement (fixed)
pdf preview sizes not filterable
Reported by: | nosilver4u | Owned by: | joemcgill |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | Media | Keywords: | has-patch 2nd-opinion |
Focuses: | Cc: |
Description
When checking the new PDF previews in 4.7, and trying to ensure that EWWW Image Optimizer is compatible with the changes, I discovered that there does not seem to be a way to modify the sizes that are generated.
With image uploads, the intermediate_image_sizes_advanced filter is available to modify the sizes being generated (or take other action, and EWWW does both).
From what I can see, the thumb generation section for PDF files in wp-admin/includes/image.php has absolutely no actions/filters for developers to modify the default behavior. I don't know if adding the intermediate_image_sizes_advanced filter is the correct way to do it, or if a new filter is in order here, but either would be greatly appreciated!
Attachments (2)
Change History (18)
#1
@
8 years ago
- Keywords reporter-feedback needs-patch added
- Owner set to joemcgill
- Status changed from new to reviewing
This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.
8 years ago
#3
@
8 years ago
I do want to emphasize that EWWW does make use of the ability to filter the resizes generated. EWWW Image Optimizer gives users the ability to disable the creation of certain resizes, and it would be nice to extend this to the realm of pdf previews as well.
The other thing that several IO plugins have is the ability to disable optimization of specific resizes, and this is where we get into the 'take other action' part of the deal:
EWWW IO extends the WP_Image_Editor class to make sure all images saved by WP_Image_Editor are optimized. To ensure that the specified resizes do not get optimized accidentally by the WP_Image_Editor extension, EWWW uses the intermediate_image_sizes_advanced filter to remove the wp_image_editors filter, and then restores the wp_image_editors filter during the wp_generate_attachment_metadata filter.
I wanted to do it as late as possible in the processing, so that any images that other plugins might generate along the way still get optimized (both before AND after the creation of resizes). So they are basically just pass-through filters toggling EWWW's WP_Image_Editor class. The only example I can think of off-hand is retina images, but there are probably others too.
#4
@
8 years ago
- Keywords has-patch 2nd-opinion added; needs-patch removed
38594.diff demonstrates how we might apply a separate filter, fallback_intermediate_image_sizes
(name is debatable) for modifying which image sizes are generated for PDFs (or other future potential files). Also note that we would want to check whether any sizes exist before running the multi-resize process so someone could filter the sizes to an empty array or false
to disable PDF thumbnails altogether.
This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.
8 years ago
#6
@
8 years ago
The 'fallback' term is a bit odd, since there isn't anything it is 'falling back' from, right? Perhaps something that indicates these are 'preview' image sizes?
This ticket was mentioned in Slack in #core-media by mike. View the logs.
8 years ago
#9
@
8 years ago
- Keywords reporter-feedback 2nd-opinion removed
- Milestone changed from Awaiting Review to 4.7
- Status changed from reviewing to accepted
Let's do something like 38594.diff for 4.7. I picked the name fallback_intermediate_image_sizes
since these thumbnails are fallbacks for media types that aren't images, but am open to better suggestions.
This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.
8 years ago
#12
@
8 years ago
- Keywords 2nd-opinion added; commit removed
38594.2.diff modifies the fallback logic so the fallback_intermediate_image_sizes
filter could be used to short circuit loading PDFs into an image editor if no fallback sizes have been defined.
However, a downside to this approach is potentially limiting folks who want to generate the full size but not any intermediate sizes as @mikeschroder mentioned in our discussion on Slack. I'm not convinced we need to add an extra filter to support that use case, since someone could create approximation of a full size if they needed to using this same filter.
Thanks @nosilver4u. As you mentioned, I don't think we would want to use the same
intermediate_image_sizes_advanced
filter here since the intent (at least for now) is to produce a limited number of intermediate sizes for the purpose of showing image representations of the PDFs in the media library, but I could see wanting a filter here.Could you give more detail about what you mean by "or take other action"? I'm curious what other types of actions you would be wanting do take at that point in the metadata generation process, and if you could hook into
wp_generate_attachment_metadata
as an alternative.