mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Media: Output WebP by default when uploading JPEGs.
Uploaded JPEGs will automatically be converted to WebP sub-sizes instead of JPEG, saving space and making sites faster. The original JPEG upload is always retained and can be accessed by calling `wp_get_original_image_url`. Props azaozz, flixos90. Fixes #55443. git-svn-id: https://develop.svn.wordpress.org/trunk@54086 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -424,19 +424,26 @@ abstract class WP_Image_Editor {
|
||||
return array( $filename, $new_ext, $mime_type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an output filename based on current file, and adding proper suffix
|
||||
/**
|
||||
* Builds an output filename based on current file, and adding proper suffix.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @since 6.1.0 Skips adding a suffix when set to an empty string. When the
|
||||
* file extension being generated doesn't match the image file extension,
|
||||
* add the extension to the suffix
|
||||
*
|
||||
* @param string $suffix
|
||||
* @param string $dest_path
|
||||
* @param string $extension
|
||||
* @return string filename
|
||||
* @param string $suffix Optional. Suffix to add to the filename. The default null
|
||||
* will result in a 'widthxheight' suffix. Passing
|
||||
* an empty string will result in no suffix.
|
||||
* @param string $dest_path Optional. The path to save the file to. The default null
|
||||
* will use the image file path.
|
||||
* @param string $extension Optional. The file extension to use. The default null
|
||||
* will use the image file extension.
|
||||
* @return string filename The generated file name.
|
||||
*/
|
||||
public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) {
|
||||
// $suffix will be appended to the destination filename, just before the extension.
|
||||
if ( ! $suffix ) {
|
||||
if ( null === $suffix ) {
|
||||
$suffix = $this->get_suffix();
|
||||
}
|
||||
|
||||
@@ -457,7 +464,21 @@ abstract class WP_Image_Editor {
|
||||
}
|
||||
}
|
||||
|
||||
return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}";
|
||||
if ( empty( $suffix ) ) {
|
||||
$suffix = '';
|
||||
} else {
|
||||
$suffix = "-{$suffix}";
|
||||
}
|
||||
|
||||
// When the file extension being generated doesn't match the image file extension,
|
||||
// add the extension to the suffix to ensure a unique file name. Prevents
|
||||
// name conflicts when a single image type can have multiple extensions,
|
||||
// eg. .jpg, .jpeg and .jpe are all valid JPEG extensions.
|
||||
if ( ! empty( $extension ) && $extension !== $ext ) {
|
||||
$suffix .= "-{$ext}";
|
||||
}
|
||||
|
||||
return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user