Skip to content

Commit 3b3d7eb

Browse files
committed
Media: Revert WebP generation.
Given [https://make.wordpress.org/core/2022/09/11/webp-in-core-for-6-1/ Matt's recent post about removing WebP from core] and possibly implementing the feature in a future [https://make.wordpress.org/core/2022/09/11/canonical-plugins-revisited/ "Canonical Plugin"], this change reverts changesets [54086], [54094], and [54097]. Additionally, [54210] contained a coding standards follow-up in one of the affected files that is no longer needed. Reverts [54086], [54094], and [54097]. Props SergeyBiryukov. See #55443. git-svn-id: https://develop.svn.wordpress.org/trunk@54226 602fd350-edb4-49c9-b593-d223f7449a82
1 parent cc3cb33 commit 3b3d7eb

17 files changed

+34
-341
lines changed

src/wp-admin/includes/image-edit.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,12 +917,10 @@ function wp_save_image( $post_id ) {
917917
}
918918

919919
// Save the full-size file, also needed to create sub-sizes.
920-
$saved = wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id );
921-
if ( ! $saved ) {
920+
if ( ! wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ) ) {
922921
$return->error = esc_js( __( 'Unable to save the image.' ) );
923922
return $return;
924923
}
925-
$new_path = $saved['path'];
926924

927925
if ( 'nothumb' === $target || 'all' === $target || 'full' === $target || $scaled ) {
928926
$tag = false;

src/wp-admin/includes/image.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,6 @@ function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id ) {
451451

452452
if ( method_exists( $editor, 'make_subsize' ) ) {
453453
foreach ( $new_sizes as $new_size_name => $new_size_data ) {
454-
// Include size name in the data.
455-
$new_size_data['name'] = $new_size_name;
456-
457454
$new_size_meta = $editor->make_subsize( $new_size_data );
458455

459456
if ( is_wp_error( $new_size_meta ) ) {

src/wp-includes/class-wp-image-editor-gd.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ protected function _resize( $max_w, $max_h, $crop = false ) {
227227
* @since 3.5.0
228228
*
229229
* @param array $sizes {
230-
* Associative array of image size names and their data.
230+
* An array of image size data arrays.
231231
*
232232
* Either a height or width must be provided.
233233
* If one of the two is set to null, the resize will
@@ -247,9 +247,6 @@ public function multi_resize( $sizes ) {
247247
$metadata = array();
248248

249249
foreach ( $sizes as $size => $size_data ) {
250-
// Include size name in the data.
251-
$size_data['name'] = $size;
252-
253250
$meta = $this->make_subsize( $size_data );
254251

255252
if ( ! is_wp_error( $meta ) ) {
@@ -264,15 +261,13 @@ public function multi_resize( $sizes ) {
264261
* Create an image sub-size and return the image meta data value for it.
265262
*
266263
* @since 5.3.0
267-
* @since 6.1.0 The $sizes parameter may now include a $name key for each entry.
268264
*
269265
* @param array $size_data {
270266
* Array of size data.
271267
*
272-
* @type int $width The maximum width in pixels.
273-
* @type int $height The maximum height in pixels.
274-
* @type bool $crop Whether to crop the image to exact dimensions.
275-
* @type string $name Image size name.
268+
* @type int $width The maximum width in pixels.
269+
* @type int $height The maximum height in pixels.
270+
* @type bool $crop Whether to crop the image to exact dimensions.
276271
* }
277272
* @return array|WP_Error The image data array for inclusion in the `sizes` array in the image meta,
278273
* WP_Error object on error.
@@ -282,8 +277,7 @@ public function make_subsize( $size_data ) {
282277
return new WP_Error( 'image_subsize_create_error', __( 'Cannot resize the image. Both width and height are not set.' ) );
283278
}
284279

285-
$orig_size = $this->size;
286-
$orig_size_name = $this->size_name;
280+
$orig_size = $this->size;
287281

288282
if ( ! isset( $size_data['width'] ) ) {
289283
$size_data['width'] = null;
@@ -297,10 +291,6 @@ public function make_subsize( $size_data ) {
297291
$size_data['crop'] = false;
298292
}
299293

300-
if ( isset( $size_data['name'] ) ) {
301-
$this->update_size_name( $size_data['name'] );
302-
}
303-
304294
$resized = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
305295

306296
if ( is_wp_error( $resized ) ) {
@@ -310,8 +300,7 @@ public function make_subsize( $size_data ) {
310300
imagedestroy( $resized );
311301
}
312302

313-
$this->size = $orig_size;
314-
$this->size_name = $orig_size_name;
303+
$this->size = $orig_size;
315304

316305
if ( ! is_wp_error( $saved ) ) {
317306
unset( $saved['path'] );

src/wp-includes/class-wp-image-editor-imagick.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ protected function thumbnail_image( $dst_w, $dst_h, $filter_name = 'FILTER_TRIAN
438438
* @since 3.5.0
439439
*
440440
* @param array $sizes {
441-
* Associative array of image size names and their data.
441+
* An array of image size data arrays.
442442
*
443443
* Either a height or width must be provided.
444444
* If one of the two is set to null, the resize will
@@ -458,9 +458,6 @@ public function multi_resize( $sizes ) {
458458
$metadata = array();
459459

460460
foreach ( $sizes as $size => $size_data ) {
461-
// Include size name in the data.
462-
$size_data['name'] = $size;
463-
464461
$meta = $this->make_subsize( $size_data );
465462

466463
if ( ! is_wp_error( $meta ) ) {
@@ -475,15 +472,13 @@ public function multi_resize( $sizes ) {
475472
* Create an image sub-size and return the image meta data value for it.
476473
*
477474
* @since 5.3.0
478-
* @since 6.1.0 The $sizes parameter may now include a $name key for each entry.
479475
*
480476
* @param array $size_data {
481477
* Array of size data.
482478
*
483-
* @type int $width The maximum width in pixels.
484-
* @type int $height The maximum height in pixels.
485-
* @type bool $crop Whether to crop the image to exact dimensions.
486-
* @type string $name Image size name.
479+
* @type int $width The maximum width in pixels.
480+
* @type int $height The maximum height in pixels.
481+
* @type bool $crop Whether to crop the image to exact dimensions.
487482
* }
488483
* @return array|WP_Error The image data array for inclusion in the `sizes` array in the image meta,
489484
* WP_Error object on error.
@@ -493,9 +488,8 @@ public function make_subsize( $size_data ) {
493488
return new WP_Error( 'image_subsize_create_error', __( 'Cannot resize the image. Both width and height are not set.' ) );
494489
}
495490

496-
$orig_size = $this->size;
497-
$orig_size_name = $this->size_name;
498-
$orig_image = $this->image->getImage();
491+
$orig_size = $this->size;
492+
$orig_image = $this->image->getImage();
499493

500494
if ( ! isset( $size_data['width'] ) ) {
501495
$size_data['width'] = null;
@@ -509,10 +503,6 @@ public function make_subsize( $size_data ) {
509503
$size_data['crop'] = false;
510504
}
511505

512-
if ( isset( $size_data['name'] ) ) {
513-
$this->update_size_name( $size_data['name'] );
514-
}
515-
516506
$resized = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
517507

518508
if ( is_wp_error( $resized ) ) {
@@ -525,9 +515,8 @@ public function make_subsize( $size_data ) {
525515
$this->image = null;
526516
}
527517

528-
$this->size = $orig_size;
529-
$this->size_name = $orig_size_name;
530-
$this->image = $orig_image;
518+
$this->size = $orig_size;
519+
$this->image = $orig_image;
531520

532521
if ( ! is_wp_error( $saved ) ) {
533522
unset( $saved['path'] );

src/wp-includes/class-wp-image-editor.php

Lines changed: 15 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
abstract class WP_Image_Editor {
1616
protected $file = null;
1717
protected $size = null;
18-
protected $size_name = '';
1918
protected $mime_type = null;
2019
protected $output_mime_type = null;
2120
protected $default_mime_type = 'image/jpeg';
@@ -119,7 +118,7 @@ abstract public function resize( $max_w, $max_h, $crop = false );
119118
* @abstract
120119
*
121120
* @param array $sizes {
122-
* Associative array of image size names and their data. Default sizes are 'small', 'medium', 'large'.
121+
* An array of image size arrays. Default sizes are 'small', 'medium', 'large'.
123122
*
124123
* @type array ...$0 {
125124
* @type int $width Image width.
@@ -187,7 +186,7 @@ abstract public function stream( $mime_type = null );
187186
*
188187
* @since 3.5.0
189188
*
190-
* @return array {
189+
* @return int[] {
191190
* Dimensions of the image.
192191
*
193192
* @type int $width The image width.
@@ -203,9 +202,9 @@ public function get_size() {
203202
*
204203
* @since 3.5.0
205204
*
206-
* @param int $width The image width.
207-
* @param int $height The image height.
208-
* @return true True on success, false on failure.
205+
* @param int $width
206+
* @param int $height
207+
* @return true
209208
*/
210209
protected function update_size( $width = null, $height = null ) {
211210
$this->size = array(
@@ -215,28 +214,6 @@ protected function update_size( $width = null, $height = null ) {
215214
return true;
216215
}
217216

218-
/**
219-
* Gets the current image size name.
220-
*
221-
* @since 6.1.0
222-
*
223-
* @return string Image size name, or empty string if none set.
224-
*/
225-
public function get_size_name() {
226-
return $this->size_name;
227-
}
228-
229-
/**
230-
* Sets the current image size name.
231-
*
232-
* @since 6.1.0
233-
*
234-
* @param string $size_name The image size name.
235-
*/
236-
protected function update_size_name( $size_name ) {
237-
$this->size_name = (string) $size_name;
238-
}
239-
240217
/**
241218
* Gets the Image Compression quality on a 1-100% scale.
242219
*
@@ -388,7 +365,6 @@ protected function get_output_format( $filename = null, $mime_type = null ) {
388365
* @see WP_Image_Editor::get_output_format()
389366
*
390367
* @since 5.8.0
391-
* @since 6.1.0 The $size_name parameter was added.
392368
*
393369
* @param string[] $output_format {
394370
* An array of mime type mappings. Maps a source mime type to a new
@@ -398,9 +374,8 @@ protected function get_output_format( $filename = null, $mime_type = null ) {
398374
* }
399375
* @param string $filename Path to the image.
400376
* @param string $mime_type The source image mime type.
401-
* @param string $size_name The image size name to create, or empty string if not set.
402377
*/
403-
$output_format = apply_filters( 'image_editor_output_format', array(), $filename, $mime_type, $this->size_name );
378+
$output_format = apply_filters( 'image_editor_output_format', array(), $filename, $mime_type );
404379

405380
if ( isset( $output_format[ $mime_type ] )
406381
&& $this->supports_mime_type( $output_format[ $mime_type ] )
@@ -450,26 +425,19 @@ protected function get_output_format( $filename = null, $mime_type = null ) {
450425
return array( $filename, $new_ext, $mime_type );
451426
}
452427

453-
/**
454-
* Builds an output filename based on current file, and adding proper suffix.
428+
/**
429+
* Builds an output filename based on current file, and adding proper suffix
455430
*
456431
* @since 3.5.0
457-
* @since 6.1.0 Skips adding a suffix when set to an empty string. When the
458-
* file extension being generated doesn't match the image file extension,
459-
* add the extension to the suffix
460-
*
461-
* @param string $suffix Optional. Suffix to add to the filename. The default null
462-
* will result in a 'widthxheight' suffix. Passing
463-
* an empty string will result in no suffix.
464-
* @param string $dest_path Optional. The path to save the file to. The default null
465-
* will use the image file path.
466-
* @param string $extension Optional. The file extension to use. The default null
467-
* will use the image file extension.
468-
* @return string filename The generated file name.
432+
*
433+
* @param string $suffix
434+
* @param string $dest_path
435+
* @param string $extension
436+
* @return string filename
469437
*/
470438
public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) {
471439
// $suffix will be appended to the destination filename, just before the extension.
472-
if ( null === $suffix ) {
440+
if ( ! $suffix ) {
473441
$suffix = $this->get_suffix();
474442
}
475443

@@ -490,21 +458,7 @@ public function generate_filename( $suffix = null, $dest_path = null, $extension
490458
}
491459
}
492460

493-
if ( empty( $suffix ) ) {
494-
$suffix = '';
495-
} else {
496-
$suffix = "-{$suffix}";
497-
}
498-
499-
// When the file extension being generated doesn't match the image file extension,
500-
// add the extension to the suffix to ensure a unique file name. Prevents
501-
// name conflicts when a single image type can have multiple extensions,
502-
// eg. .jpg, .jpeg and .jpe are all valid JPEG extensions.
503-
if ( ! empty( $extension ) && $extension !== $ext ) {
504-
$suffix .= "-{$ext}";
505-
}
506-
507-
return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}";
461+
return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}";
508462
}
509463

510464
/**

src/wp-includes/default-filters.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,6 @@
636636
add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 );
637637
add_filter( 'media_send_to_editor', 'image_media_send_to_editor', 10, 3 );
638638

639-
add_filter( 'image_editor_output_format', 'wp_default_image_output_mapping', 10, 4 );
640-
641639
// Embeds.
642640
add_action( 'rest_api_init', 'wp_oembed_register_route' );
643641
add_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 );

src/wp-includes/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2690,7 +2690,7 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
26902690
*/
26912691
if ( $is_image ) {
26922692
/** This filter is documented in wp-includes/class-wp-image-editor.php */
2693-
$output_formats = apply_filters( 'image_editor_output_format', array(), $_dir . $filename, $mime_type, '' );
2693+
$output_formats = apply_filters( 'image_editor_output_format', array(), $_dir . $filename, $mime_type );
26942694
$alt_types = array();
26952695

26962696
if ( ! empty( $output_formats[ $mime_type ] ) ) {

src/wp-includes/media.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3926,51 +3926,6 @@ function _wp_image_editor_choose( $args = array() ) {
39263926
return false;
39273927
}
39283928

3929-
/**
3930-
* Filters the default image output mapping.
3931-
*
3932-
* With this filter callback, WebP image files will be generated for certain JPEG source files.
3933-
*
3934-
* @since 6.1.0
3935-
*
3936-
* @param array $output_mapping Map of mime type to output format.
3937-
* @param string $filename Path to the image.
3938-
* @param string $mime_type The source image mime type.
3939-
* @param string $size_name Optional. The image size name to create, or empty string if not set. Default empty string.
3940-
* @return array The adjusted default output mapping.
3941-
*/
3942-
function wp_default_image_output_mapping( $output_mapping, $filename, $mime_type, $size_name = '' ) {
3943-
// If size name is specified, check whether the size supports additional MIME types like WebP.
3944-
if ( $size_name ) {
3945-
// Include only the core sizes that do not rely on add_image_size(). Additional image sizes are opt-in.
3946-
$enabled_sizes = array(
3947-
'thumbnail' => true,
3948-
'medium' => true,
3949-
'medium_large' => true,
3950-
'large' => true,
3951-
'post-thumbnail' => true,
3952-
);
3953-
3954-
/**
3955-
* Filters the sizes that support secondary mime type output. Developers can use this
3956-
* to control the generation of additional mime type sub-sized images.
3957-
*
3958-
* @since 6.1.0
3959-
*
3960-
* @param array $enabled_sizes Map of size names and whether they support secondary mime type output.
3961-
*/
3962-
$enabled_sizes = apply_filters( 'wp_image_sizes_with_additional_mime_type_support', $enabled_sizes );
3963-
3964-
// Bail early if the size does not support additional MIME types.
3965-
if ( empty( $enabled_sizes[ $size_name ] ) ) {
3966-
return $output_mapping;
3967-
}
3968-
}
3969-
3970-
$output_mapping['image/jpeg'] = 'image/webp';
3971-
return $output_mapping;
3972-
}
3973-
39743929
/**
39753930
* Prints default Plupload arguments.
39763931
*

0 commit comments

Comments
 (0)