wp_constrain_dimensions [ WordPress Function ]
wp_constrain_dimensions ( $current_width, $current_height, $max_width = 0, $max_height = 0 )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Benzer Fonksiyonlar: wp_shrink_dimensions, wp_expand_dimensions, wp_count_comments, wp_get_post_revisions, wp_stream_image
Calculates the new dimensions for a downsampled image.
If either width or height are empty, no constraint is applied on that dimension.
Source
<?php
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;
$did_width = $did_height = false;
if ( $max_width > 0 && $current_width > 0 && $current_width > $max_width ) {
$width_ratio = $max_width / $current_width;
$did_width = true;
}
if ( $max_height > 0 && $current_height > 0 && $current_height > $max_height ) {
$height_ratio = $max_height / $current_height;
$did_height = true;
}
// Calculate the larger/smaller ratios
$smaller_ratio = min( $width_ratio, $height_ratio );
$larger_ratio = max( $width_ratio, $height_ratio );
if ( intval( $current_width * $larger_ratio ) > $max_width || intval( $current_height * $larger_ratio ) > $max_height )
// The larger ratio is too big. It would result in an overflow.
$ratio = $smaller_ratio;
else
// The larger ratio fits, and is likely to be a more "snug" fit.
$ratio = $larger_ratio;
$w = intval( $current_width * $ratio );
$h = intval( $current_height * $ratio );
// Sometimes, due to rounding, we'll end up with a result like this: 465x700 in a 177x177 box is 117x176... a pixel short
// We also have issues with recursive calls resulting in an ever-changing result. Constraining to the result of a constraint should yield the original result.
// Thus we look for dimensions that are one pixel shy of the max value and bump them up
if ( $did_width && $w == $max_width - 1 )
$w = $max_width; // Round it up
if ( $did_height && $h == $max_height - 1 )
$h = $max_height; // Round it up
return array( $w, $h );
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/wp constrain dimensions « WordPress Codex
Description. Calculates the new dimensions for a down sampled image. If either width or height are empty, no constraint is applied on that dimension.
codex.wordpress.org - WordPress › Support » wp_constrain_dimensions
wp_constrain_dimensions (1 post). artemhp. Member Posted 1 year ago #. Please, help me to find man for the function wp_constrain_dimensions ...
wordpress.org - wp_constrain_dimensions (WordPress Function) - WPSeek.com
WordPress lookup for wp_constrain_dimensions, a WordPress Function. wpseek. com is a WordPress-centric search tool for developers and theme authors.
wpseek.com - wp_constrain_dimensions
Function and Method Cross Reference. wp_constrain_dimensions(). Defined at: / wp-includes/media.php -> line 266. Referenced 10 times: ...
phpxref.ftwr.co.uk