Plugin Directory

Changeset 1754829


Ignore:
Timestamp:
10/29/2017 06:25:24 PM (8 years ago)
Author:
alexvorn2
Message:

Update a little the image resize function.

Location:
resize-images-in-posts/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • resize-images-in-posts/trunk/includes/image-resize.php

    r1576551 r1754829  
    1111    $defaults = array(
    1212        'thumbnail_url'                      => '',
     13        'thumbnail_post_id'                  => '',
    1314        'thumbnail_id'                       => '',
    1415        'thumbnail_width'                    => 0,
     
    1617        'thumbnail_crop'                     => false,
    1718        'thumbnail_quality'                  => 90,
    18         'thumbnail_resize_gif'               => true
     19        'thumbnail_resize_gif'               => true,
     20        'thumbnail_download_external_site'   => false
    1921    );
    2022   
     
    2325    // If we have no thumbnail_url value
    2426    if ( empty( $instance['thumbnail_url'] ) ) {
    25         $thumbnail_url = get_post_meta( get_the_ID(), 'image', true );
     27        if ( ! empty( $instance['thumbnail_post_id'] ) ) {
     28            $post_id = $instance['thumbnail_post_id'];
     29        } else {
     30            $post_id = get_the_ID();
     31        }
     32       
     33        $thumbnail_url = get_post_meta( $post_id, 'image', true );
    2634       
    2735        if ( ! empty( $thumbnail_url ) ) {
    2836            $instance['thumbnail_url'] = $thumbnail_url;
    2937        } else {
    30             $instance['thumbnail_id'] = get_post_thumbnail_id();
     38            if ( empty( $instance['thumbnail_id'] ) ) {
     39                $instance['thumbnail_id'] = get_post_thumbnail_id( $post_id );
     40            }
    3141        }
    3242    }
     
    3949
    4050    if ( ! empty( $instance['thumbnail_url'] ) ) {
    41        
    42         // Image located into uploads folder
    4351        $return = resize_images_in_posts__dynamically_image_resize_base( $instance );
    4452    }
     
    8795                $crop_in_url .= '-c';
    8896               
    89                 if ( ! ( (string) $x == 'center' and (string) $y == 'center' )  ) {
     97                if ( ! ( (string) $x == 'center' and (string) $y == 'center' ) ) {
    9098                    $crop_in_url .= '-' . (string) $x . '-' . (string) $y;
    9199                }
     
    128136
    129137                    if ( ! file_exists( $image_file_resized ) ) {
     138
    130139                        if ( file_exists( $image_file ) and function_exists( 'getimagesize' ) ) {
    131140                            $original_image_sizes = @getimagesize( $image_file );
     
    135144                                $orig_h = $original_image_sizes[1];
    136145
    137                                 // If the original width and height are smaller than desired width and height
     146                                // If the original width and height are smaller than desired width and height we don't want to resize it
    138147                                if ( ( (int) $instance['thumbnail_width'] >= (int) $orig_w and (int) $instance['thumbnail_height'] >= (int) $orig_h ) or ( (int) $instance['thumbnail_width'] == 0 and (int) $instance['thumbnail_height'] == 0 ) ) {
    139                                     $additional_info_url = '';
    140                                    
    141148                                    $image_resize_dimensions = true;
    142149                                   
    143150                                    $new_w = $orig_w;
    144151                                    $new_h = $orig_h;
     152                                   
     153                                    $additional_info_url = '';
    145154                                } else {
    146155                                    $image_resize_dimensions = image_resize_dimensions( (int) $orig_w, (int) $orig_h, (int) $instance['thumbnail_width'], (int) $instance['thumbnail_height'], $instance['thumbnail_crop'] );
    147156                                   
    148                                     $new_w = $image_resize_dimensions[4];
    149                                     $new_h = $image_resize_dimensions[5];
    150            
    151                                     $additional_info_url = '-' . (int) $new_w . 'x' . (int) $new_h . $crop_in_url;
     157                                    // if the resulting image would be the same size or larger we don't want to resize it
     158                                    if ( $image_resize_dimensions === false ) {
     159                                        $image_resize_dimensions = true;
     160                                       
     161                                        $new_w = $orig_w;
     162                                        $new_h = $orig_h;
     163                                       
     164                                        $additional_info_url = '';
     165                                    } else {
     166                                        $new_w = $image_resize_dimensions[4];
     167                                        $new_h = $image_resize_dimensions[5];
     168               
     169                                        $additional_info_url = '-' . (int) $new_w . 'x' . (int) $new_h . $crop_in_url;
     170                                    }
    152171                                }
    153172
     
    168187                                            $image->save( $image_file_resized );
    169188
    170                                             $resize_images_in_posts__image = array(
     189                                            $result_image = array(
    171190                                                'url'              => $image_url_resized,
    172191                                                'width'            => (int) $new_w,
    173192                                                'height'           => (int) $new_h,
    174193                                                'crop'             => $instance['thumbnail_crop'],
    175                                                 'original_url'     => $url_decoded,
    176                                                 'is_local_file'    => true
     194                                                'original_url'     => $url_decoded
    177195                                            );
    178196
    179                                             $return = $resize_images_in_posts__image;
     197                                            $return = $result_image;
    180198                                        }
    181199                                    } else {
    182200                                   
    183                                         $resize_images_in_posts__image = array(
     201                                        $result_image = array(
    184202                                            'url'              => $image_url_resized,
    185203                                            'width'            => (int) $new_w,
    186204                                            'height'           => (int) $new_h,
    187205                                            'crop'             => $instance['thumbnail_crop'],
    188                                             'original_url'     => $url_decoded,
    189                                             'is_local_file'    => true
     206                                            'original_url'     => $url_decoded
    190207                                        );
    191208
    192                                         $return = $resize_images_in_posts__image;
     209                                        $return = $result_image;
    193210                                    }
    194211                                }
     
    196213                        }
    197214                    } else {
    198                         $resize_images_in_posts__image = array(
     215                        $result_image = array(
    199216                            'url'              => $image_url_resized,
    200217                            'width'            => (int) $instance['thumbnail_width'],
    201218                            'height'           => (int) $instance['thumbnail_height'],
    202219                            'crop'             => $instance['thumbnail_crop'],
    203                             'original_url'     => $url_decoded,
    204                             'is_local_file'    => true
     220                            'original_url'     => $url_decoded
    205221                        );
    206222
    207                         $return = $resize_images_in_posts__image;
     223                        $return = $result_image;
    208224                    }
    209225                }
  • resize-images-in-posts/trunk/readme.txt

    r1597477 r1754829  
    1212
    1313== Description ==
     14
     15This is a WordPress plugin.
    1416
    1517If you want to resize images in your posts automatically so the page will load faster and use less bandwidth then this plugin can help you.
     
    6163== Changelog ==
    6264
     65= 4.3 =
     66* Updated a little image resize function
     67
    6368= 4.2 =
    6469* Fix site info value
  • resize-images-in-posts/trunk/resize-images-in-posts.php

    r1597477 r1754829  
    4444        /** Versions **********************************************************/
    4545       
    46         $this->version         = '4.2';
     46        $this->version         = '4.3';
    4747
    4848        // Setup some base path and URL information
Note: See TracChangeset for help on using the changeset viewer.