image_resize
函数
image_resize ( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 )
- 参数
-
-
(string)
$file
Image file path.- Required: 是
-
(int)
$max_w
Maximum width to resize to.- Required: 是
-
(int)
$max_h
Maximum height to resize to.- Required: 是
-
(bool)
$crop
Optional. Whether to crop image or resize. Default false.- Required: 否
- Default: false
-
(string)
$suffix
Optional. File suffix. Default null.- Required: 否
- Default: null
-
(string)
$dest_path
Optional. New image file path. Default null.- Required: 否
- Default: null
-
(int)
$jpeg_quality
Optional. Image quality percentage. Default 90.- Required: 否
- Default: 90
-
(string)
- 返回值
-
- (mixed) WP_Error on failure. String with new destination path.
- 相关
-
- wp_get_image_editor()
- 定义位置
-
-
wp-includes/deprecated.php
, line 3238
-
wp-includes/deprecated.php
- 引入
- 2.5.0
- 弃用
- 3.5.0
缩小图像以适应一个特定的尺寸,并保存一个新的图像副本。
使用该函数,PNG的透明度将被保留,图像类型也是如此。如果进入的文件是PNG,那么调整后的图像也将是PNG。唯一支持的图像类型是PNG、GIF和JPEG。
有些功能需要API的存在,所以有些PHP版本可能会失去支持。这不是WordPress的错(功能被降级,而不是实际的缺陷),而是你的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; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。