注册新的图像大小。
原型
add_image_size( string $name, int $width, int $height, bool|array $crop = false )
描述
图像大小的裁剪行为取决于$ crop的值:
参数
$name
(string)
(Required)
图像大小标识符。
$width
(int)
(Required)
图像宽度(像素)。
$height
(int)
(Required)
图像高度(像素)。
$crop
(bool|array)
(Optional)
是否将图像裁剪为指定的宽度和高度或调整大小。数组可以指定裁剪区域的位置。
源文件
路径:wp-includes/media.php
<?php
...
function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
global $_wp_additional_image_sizes;
$_wp_additional_image_sizes[ $name ] = array(
'width' => absint( $width ),
'height' => absint( $height ),
'crop' => $crop,
);
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/add_image_size/