WordPress.org

Plugin Directory

Changeset 622713


Ignore:
Timestamp:
11/08/12 21:46:29 (18 months ago)
Author:
ethitter
Message:

Update Photon to better accomodate images without specified dimensions, or which don't specify both a width and height. Makes better use of the Photon API by changing the transformation based on whether or not dimensions are available, and which dimensions are available.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • jetpack/trunk/modules/photon.php

    r622640 r622713  
    8787            foreach ( $images[0] as $index => $tag ) { 
    8888                $src = $src_orig = $images[2][ $index ]; 
     89 
     90                // Default to resize, though fit may be used in certain cases where a dimension cannot be ascertained 
     91                $transform = 'resize'; 
    8992 
    9093                // Check if image URL should be used with Photon 
     
    117120                        $width = $content_width; 
    118121                    } 
    119  
    120                     if ( false === $height ) 
    121                         $height = 9999; 
    122122                } 
    123123 
    124124                // Set a width if none is found and height is available, either $content_width or a very large value 
    125125                // Large value is used so as to not unnecessarily constrain image when passed to Photon 
    126                 if ( false === $width && false !== $height ) 
     126                if ( false === $width && false !== $height ) { 
    127127                    $width = is_numeric( $content_width ) ? (int) $content_width : 9999; 
    128  
    129                 // Set a height if none is found and width is available, using a large value 
    130                 if ( false === $height && false !== $width ) 
    131                     $height = 9999; 
     128                    $transform = 'fit'; 
     129                } 
    132130 
    133131                // As a last resort, ensure that image won't be larger than $content_width if it is set. 
    134                 if ( false === $width && is_numeric( $content_width ) ) { 
     132                if ( false === $width && is_numeric( $content_width ) ) 
    135133                    $width = (int) $content_width; 
    136                     $height = 9999; 
    137                 } 
    138134 
    139135                // Build URL, first removing WP's resized string so we pass the original image to Photon 
     
    145141 
    146142                if ( false !== $width && false !== $height ) 
    147                     $args['resize'] = $width . ',' . $height; 
     143                    $args[ $transform ] = $width . ',' . $height; 
     144                elseif ( false !== $width ) 
     145                    $args['w'] = $width; 
     146                elseif ( false !== $height ) 
     147                    $args['h'] = $height; 
    148148 
    149149                $args = apply_filters( 'jetpack_photon_post_image_args', $args, compact( 'tag', 'src', 'src_orig', 'width', 'height' ) ); 
Note: See TracChangeset for help on using the changeset viewer.