image_resize_dimensions [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Retrieve calculated resized dimensions for use in imagecopyresampled().
Calculate dimensions and coordinates for a resized image that fits within a specified width and height. If $crop is true, the largest matching central portion of the image will be cropped out and resized to the required size.
Source
<?php
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) {
if ($orig_w <= 0 || $orig_h <= 0)
return false;
// at least one of dest_w or dest_h must be specific
if ($dest_w <= 0 && $dest_h <= 0)
return false;
// plugins can use this to provide custom resize dimensions
$output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop );
if ( null !== $output )
return $output;
if ( $crop ) {
// crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
$aspect_ratio = $orig_w / $orig_h;
$new_w = min($dest_w, $orig_w);
$new_h = min($dest_h, $orig_h);
if ( !$new_w ) {
$new_w = intval($new_h * $aspect_ratio);
}
if ( !$new_h ) {
$new_h = intval($new_w / $aspect_ratio);
}
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
$crop_w = round($new_w / $size_ratio);
$crop_h = round($new_h / $size_ratio);
$s_x = floor( ($orig_w - $crop_w) / 2 );
$s_y = floor( ($orig_h - $crop_h) / 2 );
} else {
// don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
$crop_w = $orig_w;
$crop_h = $orig_h;
$s_x = 0;
$s_y = 0;
list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
}
// if the resulting image would be the same size or larger we don't want to resize it
if ( $new_w >= $orig_w && $new_h >= $orig_h )
return false;
// the return array matches the parameters to imagecopyresampled()
// int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/image resize dimensions « WordPress Codex
Description. Retrieve calculated resized dimensions for use in imagecopyresampled(). Calculate dimensions and coordinates for a resized image that fits within ...
codex.wordpress.org - #15989 (image_resize_dimensions() mistakenly defaults crop ...
2- Modify image_resize_dimensions() to accept optional $x=0, $y=0 and allowing , ultimately, the selection of those values in the Multimedia Editor by the user, ...
core.trac.wordpress.org - image_resize_dimensions | image.effects.inc | Drupal 7 | Drupal API
7 image.effects.inc, image_resize_dimensions(array &$dimensions, array $data). 8 image.effects.inc · image_resize_dimensions(array &$dimensions, array ...
api.drupal.org - image_resize_dimensions (WordPress Function) - WPSeek.com
WordPress lookup for image_resize_dimensions, a WordPress Function. wpseek .com is a WordPress-centric search tool for developers and theme authors.
wpseek.com