加载图像资源以进行编辑。
原型
load_image_to_edit( string $attachment_id, string $mime_type, string $size = 'full' )
参数
$attachment_id
(string)
(Required)
附件ID。
$mime_type
(string)
(Required)
图像mime类型。
$size
(string)
(Optional)
图像大小,默认为“完整”。
返回值
(resource|false)
生成的图像资源成功,失败时为false。
源文件
路径:wp-admin/includes/image.php
<?php
...
function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) {
$filepath = _load_image_to_edit_path( $attachment_id, $size );
if ( empty( $filepath ) )
return false;
switch ( $mime_type ) {
case 'image/jpeg':
$image = imagecreatefromjpeg($filepath);
break;
case 'image/png':
$image = imagecreatefrompng($filepath);
break;
case 'image/gif':
$image = imagecreatefromgif($filepath);
break;
default:
$image = false;
break;
}
if ( is_resource($image) ) {
/**
* Filters the current image being loaded for editing.
*
* @since 2.9.0
*
* @param resource $image Current image.
* @param string $attachment_id Attachment ID.
* @param string $size Image size.
*/
$image = apply_filters( 'load_image_to_edit', $image, $attachment_id, $size );
if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) {
imagealphablending($image, false);
imagesavealpha($image, true);
}
}
return $image;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/load_image_to_edit/