load_image_to_edit
函数
load_image_to_edit ( $attachment_id, $mime_type, $size = 'full' )
- 参数
-
-
(int)
$attachment_id
Attachment ID.- Required: 是
-
(string)
$mime_type
Image mime type.- Required: 是
-
(string|int[])
$size
Optional. Image size. Accepts any registered image size name, or an array of width and height values in pixels (in that order). Default ‘full’.- Required: 否
- Default: ‘full’
-
(int)
- 返回值
-
- (resource|GdImage|false) The resulting image resource or GdImage instance on success, false on failure.
- 定义位置
-
-
wp-admin/includes/image.php
, line 1007
-
wp-admin/includes/image.php
- 引入
- 2.9.0
- 弃用
- –
加载一个用于编辑的图像资源。
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;
case 'image/webp':
$image = false;
if ( function_exists( 'imagecreatefromwebp' ) ) {
$image = imagecreatefromwebp( $filepath );
}
break;
default:
$image = false;
break;
}
if ( is_gd_image( $image ) ) {
/**
* Filters the current image being loaded for editing.
*
* @since 2.9.0
*
* @param resource|GdImage $image Current image.
* @param int $attachment_id Attachment ID.
* @param string|int[] $size Requested image size. Can be any registered image size name, or
* an array of width and height values in pixels (in that order).
*/
$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;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。


