Skip to content

Output WebP by default for core sizes #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 117 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
a96ea8a
Core patch, first pass
adamsilverstein Mar 4, 2022
fa8b9ef
Store the sources meta
adamsilverstein Mar 6, 2022
32807da
Delete additional mime types in wp_delete_attachment_files
adamsilverstein Mar 6, 2022
c930645
Cleanup, remove unintended changes
adamsilverstein Mar 6, 2022
3db70bd
Add full size and root level meta
adamsilverstein Mar 6, 2022
62855be
Add alternate mime full sizes to wp_delete_attachment_files
adamsilverstein Mar 7, 2022
54d4346
Update image tag output to use specified mime type.
adamsilverstein Mar 7, 2022
daaacba
Ensure full size image generated, sources populated
adamsilverstein Mar 7, 2022
958e752
Handle the full size image in image tags
adamsilverstein Mar 8, 2022
80a78d1
Cleanup, documentation
adamsilverstein Mar 8, 2022
f2d0893
Unroll full sized image generation to single loop, dry out code with …
adamsilverstein Mar 8, 2022
0822850
remove duplicate editor construction
adamsilverstein Mar 8, 2022
1caa589
Merge branch 'trunk' into add/webp-uploads
adamsilverstein Mar 8, 2022
bd9a90c
Add mime type support check in loops, skip trying unsupported mime ty…
adamsilverstein Mar 8, 2022
f863431
Docblock improvements & cleanup
adamsilverstein Mar 8, 2022
cbd4ce7
Cleanup and match filter name to issue
adamsilverstein Mar 8, 2022
810818a
Add a new ‘wp_content_image_mimes’ filter for output
adamsilverstein Mar 8, 2022
892b34c
Clean up and document image replacement approach.
adamsilverstein Mar 8, 2022
0d38d2e
Add default value to make_subsize functions
adamsilverstein Mar 9, 2022
775f4ff
Add and improve tests
adamsilverstein Mar 9, 2022
e61ec6b
Add mapping for PDF images to export as jpeg
adamsilverstein Mar 9, 2022
913c157
Add ‘sources’ to test data, clean up tests
adamsilverstein Mar 9, 2022
f3b30ef
Merge branch 'trunk' into add/webp-uploads
adamsilverstein Mar 10, 2022
f2cacab
Test cleanup
adamsilverstein Mar 10, 2022
6960704
Switch all filesize calls to wp_filesize
adamsilverstein Mar 10, 2022
3c85bc1
Use root meta filesize when available vs. recalculating
adamsilverstein Mar 10, 2022
f383749
Fix test data
adamsilverstein Mar 10, 2022
cba3b43
Cleanup
adamsilverstein Mar 10, 2022
3486a08
Remove mime support checks, handled downstream already
adamsilverstein Mar 14, 2022
0afad05
Improve doc blocks, tests, cleanup
adamsilverstein Mar 14, 2022
39c17ee
Increase the maximum retry count from 4 to 8
adamsilverstein Mar 15, 2022
26ba1ee
Update src/wp-admin/includes/image.php
adamsilverstein Mar 16, 2022
92a26bb
Update src/wp-admin/includes/image.php
adamsilverstein Mar 16, 2022
9107290
Merge branch 'trunk' into add/webp-uploads
adamsilverstein Mar 18, 2022
9d7f8c8
Double retry count in plupload/handlers.js
adamsilverstein Mar 18, 2022
018b3fb
Restore most of _wp_make_subsizes, add _wp_make_additional_mime_subsi…
adamsilverstein Mar 18, 2022
9803604
Better integrate mime type loops into image creation
adamsilverstein Mar 18, 2022
2f7f383
Save meta data during intiial large -scaled/-rotated image creation
adamsilverstein Mar 20, 2022
1b11a80
Remove PDF mapping
adamsilverstein Mar 20, 2022
3a0f707
refactor deletion code into main loop, exclude main mime type
adamsilverstein Mar 20, 2022
7c0a98f
Skip attachment id 0
adamsilverstein Mar 20, 2022
73bfa12
Only transform jpeg images
adamsilverstein Mar 20, 2022
c30d709
Skip mime types that are not supported.
adamsilverstein Mar 20, 2022
1cc2d7c
Fix mime data contruction
adamsilverstein Mar 21, 2022
ec9c4f9
Ensure presence a top level sources array for the full size images
adamsilverstein Mar 21, 2022
de69a6c
Clean up full size generation
adamsilverstein Mar 21, 2022
84d1e4c
Remove sources check for now
adamsilverstein Mar 21, 2022
1e9fdc8
Restore default ‘application/pdf’ mapping
adamsilverstein Mar 21, 2022
a22dc14
When deleting, the first sources element is primary
adamsilverstein Mar 21, 2022
d7168f6
Update src/wp-admin/includes/image.php
adamsilverstein Mar 22, 2022
2192ee2
Update src/wp-admin/includes/image.php
adamsilverstein Mar 22, 2022
7c0de80
Update src/wp-admin/includes/image.php
adamsilverstein Mar 22, 2022
e781a0a
Update src/wp-includes/class-wp-image-editor-gd.php
adamsilverstein Mar 22, 2022
06151d3
Update src/wp-includes/class-wp-image-editor-imagick.php
adamsilverstein Mar 22, 2022
8c2412d
Remove remnant _wp_delete_alternate_mime_sizes
adamsilverstein Mar 22, 2022
16e3a68
Merge branch 'add/webp-uploads' of github.com:adamsilverstein/wordpre…
adamsilverstein Mar 22, 2022
9855e83
Remove editor reset in `wp_create_image_subsizes`
adamsilverstein Mar 22, 2022
a8a0e56
Update src/wp-admin/includes/image.php
adamsilverstein Mar 22, 2022
6ef7092
Remove additional editor reset in `wp_create_image_subsizes`
adamsilverstein Mar 22, 2022
f9e7954
Ensure primary mime falls back to image mime type
adamsilverstein Mar 22, 2022
0337b61
Refactor extension usage
adamsilverstein Mar 22, 2022
2d582d8
Use _wp_get_sources_from_meta for top level meta construction
adamsilverstein Mar 22, 2022
d133ef1
Move empty check into _wp_get_primary_and_additional_mime_types and c…
adamsilverstein Mar 22, 2022
fccdca8
Remove extraneous PDF mapping
adamsilverstein Mar 22, 2022
e4580c0
Add context to function call and filter (wp_content_image_mimes)
adamsilverstein Mar 22, 2022
f27e922
Use count & reverse conditional
adamsilverstein Mar 22, 2022
a55164a
Clean up deletion loops
adamsilverstein Mar 22, 2022
b757e5a
Always generate either -scaled or non scaled alternate mime FULL size…
adamsilverstein Mar 22, 2022
3ba9254
Use extension naming format for now
adamsilverstein Mar 22, 2022
cc723e8
Merge branch 'trunk' into add/webp-uploads
adamsilverstein Mar 22, 2022
9c0937c
Extract mime type and upload mime transforms in _wp_get_primary_and_a…
adamsilverstein Mar 23, 2022
db4f526
Merge branch 'trunk' into add/webp-uploads
adamsilverstein Mar 23, 2022
00dbbf9
Improve image editor integration
adamsilverstein Mar 23, 2022
c5fddab
Revert "Improve image editor integration"
adamsilverstein Mar 23, 2022
822a49b
Comment alignment
adamsilverstein Mar 23, 2022
cf481a7
Revert "Revert "Improve image editor integration""
adamsilverstein Mar 24, 2022
98ab980
Introduce reset_mime_type and mime_type_set to base image class
adamsilverstein Mar 24, 2022
7bbdef4
Merge branch 'trunk' into add/webp-uploads
adamsilverstein Mar 24, 2022
de0500d
Restructure loops putting mime types as outer
adamsilverstein Mar 25, 2022
bcf4d0a
Update src/wp-admin/includes/image.php
adamsilverstein Mar 28, 2022
d9e9d1c
Improve generate_filename suffix handling
adamsilverstein Mar 28, 2022
43afd05
Update doc blocks for wp_upload_image_mime_transforms
adamsilverstein Mar 28, 2022
3061627
Merge branch 'trunk' into add/webp-uploads
adamsilverstein Mar 28, 2022
d9e8644
Update generate_filename and doc block to enable no suffix
adamsilverstein Mar 28, 2022
af9db67
Improve logic for sub size loop
adamsilverstein Mar 28, 2022
4e36c6c
Ensure $editor available
adamsilverstein Mar 28, 2022
eaffc70
generate additional full sizes without extension
adamsilverstein Mar 28, 2022
75315ce
Use legacy JPEG output for PDF tests
adamsilverstein Mar 28, 2022
7f78dac
Calculate over threshold only once (“big_image_size_threshold”)
adamsilverstein Mar 28, 2022
253a0df
Add a root level (primary) ‘meta_type’ attribute
adamsilverstein Mar 28, 2022
4acc7c5
Ensure alternate mime -scaled images are included in sources meta
adamsilverstein Mar 28, 2022
efa33f2
Use primary mime when deleting additional sources
adamsilverstein Mar 28, 2022
133d9a6
Update src/wp-includes/post.php
adamsilverstein Mar 29, 2022
bf1c483
Update tests/phpunit/tests/image/functions.php
adamsilverstein Mar 29, 2022
4bffe64
Update src/wp-includes/class-wp-image-editor.php
adamsilverstein Mar 29, 2022
abcab3a
phpcbf
adamsilverstein Mar 29, 2022
2bd43b2
Merge branch 'trunk' into add/webp-uploads
adamsilverstein May 3, 2022
790f011
Ensure $meta['file'] set before using
adamsilverstein May 3, 2022
416f088
restore whitespace
adamsilverstein May 3, 2022
7b400ae
Merge branch 'trunk' into add/webp-uploads
adamsilverstein May 9, 2022
6a894f5
Ensure image filter skipped for test
adamsilverstein May 10, 2022
dfd6ec4
Merge branch 'trunk' into add/webp-uploads
adamsilverstein Jun 2, 2022
9ea4c64
Merge branch 'trunk' into add/webp-uploads
felixarntz Jun 6, 2022
d191861
Enhance separation of concerns in image generation logic, introduce m…
felixarntz Jun 7, 2022
688d4f9
Treat the manually set mime_type class property like a fallback for t…
felixarntz Jun 7, 2022
503134e
Update version numbers to 6.1.0.
felixarntz Jun 7, 2022
52836e8
Ensure retry mechanism works correctly and also generates full sized …
felixarntz Jun 7, 2022
47781a6
Merge branch 'trunk' into add/webp-uploads
adamsilverstein Jun 14, 2022
8f9b99e
Merge branch 'add/webp-uploads' of github.com:adamsilverstein/wordpre…
adamsilverstein Jun 14, 2022
d75e58a
fix after merge
adamsilverstein Jun 14, 2022
1589bfd
Fixes for tests
adamsilverstein Jun 14, 2022
4dbb3e7
Handle an empty value for $output_mime_types: only output the origina…
adamsilverstein Jun 16, 2022
f24edd1
Improve deletion to use sources data when available, falling back to …
adamsilverstein Jun 16, 2022
90c5196
Output WebP by default for core sizes
adamsilverstein Jun 17, 2022
6a252ff
Merge branch 'trunk' into add/webp-uploads-only-core-default
adamsilverstein Jun 20, 2023
e9a51a8
Change default mapping to WebP, restore trunk
adamsilverstein Jun 20, 2023
6232ffa
Consolidate filtering into helper to reduce duplication of code
adamsilverstein Jun 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions src/wp-includes/class-wp-image-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,26 +356,7 @@ protected function get_output_format( $filename = null, $mime_type = null ) {
$new_ext = $file_ext;
}

/**
* Filters the image editor output format mapping.
*
* Enables filtering the mime type used to save images. By default,
* the mapping array is empty, so the mime type matches the source image.
*
* @see WP_Image_Editor::get_output_format()
*
* @since 5.8.0
*
* @param string[] $output_format {
* An array of mime type mappings. Maps a source mime type to a new
* destination mime type. Default empty array.
*
* @type string ...$0 The new mime type.
* }
* @param string $filename Path to the image.
* @param string $mime_type The source image mime type.
*/
$output_format = apply_filters( 'image_editor_output_format', array(), $filename, $mime_type );
get_default_image_editor_output_format( $filename, $mime_type );

if ( isset( $output_format[ $mime_type ] )
&& $this->supports_mime_type( $output_format[ $mime_type ] )
Expand Down
43 changes: 42 additions & 1 deletion src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,7 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
*/
if ( $is_image ) {
/** This filter is documented in wp-includes/class-wp-image-editor.php */
$output_formats = apply_filters( 'image_editor_output_format', array(), $_dir . $filename, $mime_type );
$output_formats = get_default_image_editor_output_format( $_dir . $filename, $mime_type );
$alt_types = array();

if ( ! empty( $output_formats[ $mime_type ] ) ) {
Expand Down Expand Up @@ -2760,6 +2760,47 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
}
}

/**
* Get the default output format. Return is filtered by `image_editor_output_format`.
*
* @since 6.4.0
*
* @param string $filename Path to the image.
* @param string $mime_type The source image mime type.
*
* @return string[] $output_format {
* An array of mime type mappings. Maps a source mime type to a new
* destination mime type. Default maps jpeg to webp.
*
* @type string ...$0 The new mime type.
* }
*/
function get_default_image_editor_output_format( $filename, $mime_type ) {
$default = array (
'image/jpeg' => 'image/webp',
);
/**
* Filters the image editor output format mapping.
*
* Enables filtering the mime type used to save images. By default,
* the mapping array is empty, so the mime type matches the source image.
*
* @see WP_Image_Editor::get_output_format()
*
* @since 5.8.0
*
* @param string[] $output_format {
* An array of mime type mappings. Maps a source mime type to a new
* destination mime type. Default maps jpeg to webp.
*
* @type string ...$0 The new mime type.
* }
* @param string $filename Path to the image.
* @param string $mime_type The source image mime type.
*/
return apply_filters( 'image_editor_output_format', $default(), $filename, $mime_type );
}

/**
* Filters the result when generating a unique file name.
*
Expand Down
3 changes: 1 addition & 2 deletions src/wp-includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -3919,8 +3919,7 @@ function wp_get_image_editor( $path, $args = array() ) {

// Check and set the output mime type mapped to the input type.
if ( isset( $args['mime_type'] ) ) {
/** This filter is documented in wp-includes/class-wp-image-editor.php */
$output_format = apply_filters( 'image_editor_output_format', array(), $path, $args['mime_type'] );
$output_format = get_default_image_editor_output_format( $path, $args['mime_type'] );
if ( isset( $output_format[ $args['mime_type'] ] ) ) {
$args['output_mime_type'] = $output_format[ $args['mime_type'] ];
}
Expand Down