返回介绍

wp_get_image_editor()

发布于 2017-09-11 12:05:51 字数 3185 浏览 1037 评论 0 收藏 0

wp_get_image_editor( string $path,  array $args = array() )

Returns a WP_Image_Editor instance and loads file into it.


description


参数

$path

(string) (Required) Path to the file to load.

$args

(array) (Optional) Additional arguments for retrieving the image editor.

Default value: array()


返回值

(WP_Image_Editor|WP_Error) The WP_Image_Editor object if successful, an WP_Error object otherwise.


源代码

File: wp-includes/media.php

function wp_get_image_editor( $path, $args = array() ) {
	$args['path'] = $path;

	if ( ! isset( $args['mime_type'] ) ) {
		$file_info = wp_check_filetype( $args['path'] );

		// If $file_info['type'] is false, then we let the editor attempt to
		// figure out the file type, rather than forcing a failure based on extension.
		if ( isset( $file_info ) && $file_info['type'] )
			$args['mime_type'] = $file_info['type'];
	}

	$implementation = _wp_image_editor_choose( $args );

	if ( $implementation ) {
		$editor = new $implementation( $path );
		$loaded = $editor->load();

		if ( is_wp_error( $loaded ) )
			return $loaded;

		return $editor;
	}

	return new WP_Error( 'image_no_editor', __('No editor could be selected.') );
}

更新日志

Versiondescription
3.5.0Introduced.

相关函数

Uses

  • wp-includes/l10n.php: __()
  • wp-includes/functions.php: wp_check_filetype()
  • wp-includes/load.php: is_wp_error()
  • wp-includes/class-wp-error.php: WP_Error::__construct()

Used By

  • wp-admin/includes/image-edit.php: stream_preview_image()
  • wp-admin/includes/image-edit.php: wp_save_image()
  • wp-admin/includes/image.php: wp_generate_attachment_metadata()
  • wp-admin/includes/image.php: wp_crop_image()
  • wp-includes/deprecated.php: image_resize()
  • wp-includes/media.php: image_make_intermediate_size()
  • Show 1 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 4You must log in to vote on the helpfulness of this note Contributed by Codex

    Basic Example

    
    $image = wp_get_image_editor( 'cool_image.jpg' );
    if ( ! is_wp_error( $image ) ) {
        $image->rotate( 90 );
        $image->resize( 300, 300, true );
        $image->save( 'new_image.jpg' );
    }
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文