wp_constrain_dimensions
云策文档标注
概述
wp_constrain_dimensions 是一个 WordPress 过滤器,用于约束下采样图像的尺寸。它允许开发者修改图像在缩放时的宽度和高度值,以确保符合最大尺寸限制。
关键要点
- 这是一个过滤器,用于调整图像下采样时的尺寸计算。
- 参数包括当前图像的宽度和高度、最大允许的宽度和高度,以及一个包含宽度和高度值的数组。
- 常用于 wp_constrain_dimensions() 函数中,计算新尺寸。
代码示例
apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height );注意事项
- 该过滤器在 WordPress 4.1.0 版本中引入。
- 返回一个包含新宽度和高度的数组。
原文内容
Filters dimensions to constrain down-sampled images to.
Parameters
$dimensionsint[]-
An array of width and height values.
0intThe width in pixels.1intThe height in pixels.
$current_widthint-
The current width of the image.
$current_heightint-
The current height of the image.
$max_widthint-
The maximum width permitted.
$max_heightint-
The maximum height permitted.
Source
return apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height );
Changelog
| Version | Description |
|---|---|
| 4.1.0 | Introduced. |