image_resize() and friends from tellyworth. fixes #6005

git-svn-id: https://develop.svn.wordpress.org/trunk@7041 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2008-02-26 18:46:03 +00:00
parent 01f1ccaf99
commit ebf8442951
2 changed files with 134 additions and 20 deletions

View File

@@ -227,26 +227,6 @@ function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) {
return wp_constrain_dimensions( $width, $height, $wmax, $hmax );
}
// same as wp_shrink_dimensions, except the max parameters are optional.
// if either width or height are empty, no constraint is applied on that dimension.
function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, $max_height=0 ) {
if ( !$max_width and !$max_height )
return array( $current_width, $current_height );
$width_ratio = $height_ratio = 1.0;
if ( $max_width > 0 && $current_width > $max_width )
$width_ratio = $max_width / $current_width;
if ( $max_height > 0 && $current_height > $max_height )
$height_ratio = $max_height / $current_height;
// the smaller ratio is the one we need to fit it to the constraining box
$ratio = min( $width_ratio, $height_ratio );
return array( intval($current_width * $ratio), intval($current_height * $ratio) );
}
// convert a fraction string to a decimal
function wp_exif_frac2dec($str) {
@list( $n, $d ) = explode( '/', $str );