WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/07/2019 01:06:49 AM (6 weeks ago)
Author:
azaozz
Message:

Media: Add handling for "BIG" images. When the users upload a big image, typically a photo, scale it down to make it suitable for web use. Then use the scaled image as the "full" size, and keep the originally uploaded image for creating high quality sub-sizes in the future and in case the users want to download it later.

Introduces wp_get_original_image_path() that retrieves the path to the originally uploaded image in all cases, and big_image_size_threshold filter to set the pixel value above which images will be scaled. The same value is used as max-width and max-height when scaling.

See #47873.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r45932 r46076  
    56395639        if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) {
    56405640            $thumbfile = str_replace( wp_basename( $file ), $meta['thumb'], $file );
     5641
    56415642            if ( ! empty( $thumbfile ) ) {
    56425643                $thumbfile = path_join( $uploadpath['basedir'], $thumbfile );
     
    56535654    if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
    56545655        $intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) );
     5656
    56555657        foreach ( $meta['sizes'] as $size => $sizeinfo ) {
    56565658            $intermediate_file = str_replace( wp_basename( $file ), $sizeinfo['file'], $file );
     5659
    56575660            if ( ! empty( $intermediate_file ) ) {
    56585661                $intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file );
     
    56655668    }
    56665669
     5670    if ( ! empty( $meta['original_image'] ) ) {
     5671        if ( empty( $intermediate_dir ) ) {
     5672            $intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) );
     5673        }
     5674
     5675        $original_image = str_replace( wp_basename( $file ), $meta['original_image'], $file );
     5676
     5677        if ( ! empty( $original_image ) ) {
     5678            $original_image = path_join( $uploadpath['basedir'], $original_image );
     5679
     5680            if ( ! wp_delete_file_from_directory( $original_image, $intermediate_dir ) ) {
     5681                $deleted = false;
     5682            }
     5683        }
     5684    }
     5685
    56675686    if ( is_array( $backup_sizes ) ) {
    56685687        $del_dir = path_join( $uploadpath['basedir'], dirname( $meta['file'] ) );
     5688
    56695689        foreach ( $backup_sizes as $size ) {
    56705690            $del_file = path_join( dirname( $meta['file'] ), $size['file'] );
     5691
    56715692            if ( ! empty( $del_file ) ) {
    56725693                $del_file = path_join( $uploadpath['basedir'], $del_file );
Note: See TracChangeset for help on using the changeset viewer.