缩小图像以适合特定大小并保存图像的新副本。
原型
image_resize( string $file, int $max_w, int $max_h, bool $crop = false, string $suffix = null, string $dest_path = null, int $jpeg_quality = 90 )
描述
将使用该函数以及图像类型保留PNG透明度。如果进入的文件是PNG,则调整大小的图像将是PNG。唯一支持的图像类型是PNG,GIF和JPEG。
参考:
- wp_get_image_editor()
参数
$file
(string)
(Required)
图像文件路径。
$max_w
(int)
(Required)
要调整大小的最大宽度。
$max_h
(int)
(Required)
要调整大小的最大高度。
$crop
(bool)
(Optional)
是裁剪图像还是调整大小。
$suffix
(string)
(Optional)
文件后缀。
$dest_path
(string)
(Optional)
新图像文件路径。
$jpeg_quality
(int)
(Optional)
图像质量百分比。
返回值
(mixed)
源文件
路径:wp-includes/deprecated.php
<?php
...
function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
_deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' );
$editor = wp_get_image_editor( $file );
if ( is_wp_error( $editor ) )
return $editor;
$editor->set_quality( $jpeg_quality );
$resized = $editor->resize( $max_w, $max_h, $crop );
if ( is_wp_error( $resized ) )
return $resized;
$dest_file = $editor->generate_filename( $suffix, $dest_path );
$saved = $editor->save( $dest_file );
if ( is_wp_error( $saved ) )
return $saved;
return $dest_file;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/image_resize/