Changeset 59367
- Timestamp:
- 11/07/2024 01:25:10 AM (4 weeks ago)
- Location:
- branches/6.7
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.7
- Property svn:mergeinfo changed
/trunk merged: 59317,59346,59366
- Property svn:mergeinfo changed
-
branches/6.7/src/wp-admin/includes/image.php
r58849 r59367 292 292 * scale the image and use it as the "full" size. 293 293 */ 294 $scale_down = false; 295 $convert = false; 296 294 297 if ( $threshold && ( $image_meta['width'] > $threshold || $image_meta['height'] > $threshold ) ) { 298 // The image will be converted if needed on saving. 299 $scale_down = true; 300 } else { 301 // The image may need to be converted regardless of its dimensions. 302 $output_format = wp_get_image_editor_output_format( $file, $imagesize['mime'] ); 303 304 if ( 305 is_array( $output_format ) && 306 array_key_exists( $imagesize['mime'], $output_format ) && 307 $output_format[ $imagesize['mime'] ] !== $imagesize['mime'] 308 ) { 309 $convert = true; 310 } 311 } 312 313 if ( $scale_down || $convert ) { 295 314 $editor = wp_get_image_editor( $file ); 296 315 … … 300 319 } 301 320 302 // Resize the image. 303 $resized = $editor->resize( $threshold, $threshold ); 321 if ( $scale_down ) { 322 // Resize the image. This will also convet it if needed. 323 $resized = $editor->resize( $threshold, $threshold ); 324 } elseif ( $convert ) { 325 // The image will be converted (if possible) when saved. 326 $resized = true; 327 } 328 304 329 $rotated = null; 305 330 … … 307 332 if ( ! is_wp_error( $resized ) && is_array( $exif_meta ) ) { 308 333 $resized = $editor->maybe_exif_rotate(); 309 $rotated = $resized; 334 $rotated = $resized; // bool true or WP_Error 310 335 } 311 336 … … 315 340 * This doesn't affect the sub-sizes names as they are generated from the original image (for best quality). 316 341 */ 317 $saved = $editor->save( $editor->generate_filename( 'scaled' ) ); 342 if ( $scale_down ) { 343 $saved = $editor->save( $editor->generate_filename( 'scaled' ) ); 344 } else { 345 $saved = $editor->save(); 346 } 318 347 319 348 if ( ! is_wp_error( $saved ) ) { -
branches/6.7/src/wp-includes/media.php
r59360 r59367 6234 6234 */ 6235 6235 function wp_get_image_editor_output_format( $filename, $mime_type ) { 6236 $output_format = array( 6237 'image/heic' => 'image/jpeg', 6238 'image/heif' => 'image/jpeg', 6239 'image/heic-sequence' => 'image/jpeg', 6240 'image/heif-sequence' => 'image/jpeg', 6241 ); 6242 6236 6243 /** 6237 6244 * Filters the image editor output format mapping. 6238 6245 * 6239 * Enables filtering the mime type used to save images. By default ,6240 * the mapping array is empty, so the mime type matches the source image.6246 * Enables filtering the mime type used to save images. By default HEIC/HEIF images 6247 * are converted to JPEGs. 6241 6248 * 6242 6249 * @see WP_Image_Editor::get_output_format() 6243 6250 * 6244 6251 * @since 5.8.0 6245 * @since 6.7.0 The default was changed from array() to array( 'image/heic' => 'image/jpeg' ). 6252 * @since 6.7.0 The default was changed from an empty array to an array 6253 * containing the HEIC/HEIF images mime types. 6246 6254 * 6247 6255 * @param string[] $output_format { 6248 6256 * An array of mime type mappings. Maps a source mime type to a new 6249 * destination mime type. Default maps uploaded HEIC imagesto JPEG output.6257 * destination mime type. By default maps HEIC/HEIF input to JPEG output. 6250 6258 * 6251 6259 * @type string ...$0 The new mime type. … … 6254 6262 * @param string $mime_type The source image mime type. 6255 6263 */ 6256 return apply_filters( 'image_editor_output_format', array( 'image/heic' => 'image/jpeg' ), $filename, $mime_type );6257 } 6264 return apply_filters( 'image_editor_output_format', $output_format, $filename, $mime_type ); 6265 }
Note: See TracChangeset
for help on using the changeset viewer.