WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/26/2008 06:46:03 PM (12 years ago)
Author:
ryan
Message:

image_resize() and friends from tellyworth. fixes #6005

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/image.php

    r6952 r7041  
    226226function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) {
    227227    return wp_constrain_dimensions( $width, $height, $wmax, $hmax );
    228 }
    229 
    230 // same as wp_shrink_dimensions, except the max parameters are optional.
    231 // if either width or height are empty, no constraint is applied on that dimension.
    232 function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, $max_height=0 ) {
    233     if ( !$max_width and !$max_height )
    234         return array( $current_width, $current_height );
    235    
    236     $width_ratio = $height_ratio = 1.0;
    237    
    238     if ( $max_width > 0 && $current_width > $max_width )
    239         $width_ratio = $max_width / $current_width;
    240    
    241     if ( $max_height > 0 && $current_height > $max_height )
    242         $height_ratio = $max_height / $current_height;
    243    
    244     // the smaller ratio is the one we need to fit it to the constraining box
    245     $ratio = min( $width_ratio, $height_ratio );
    246    
    247     return array( intval($current_width * $ratio), intval($current_height * $ratio) );
    248228}
    249229
Note: See TracChangeset for help on using the changeset viewer.