Title: WP_Image_Editor_GD::load
Published: April 25, 2014
Last modified: February 24, 2026

---

# WP_Image_Editor_GD::load(): true|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/load/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/load/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/load/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/load/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/load/?output_format=md#wp--skip-link--target)

Loads image from $this->file into new GD Resource.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/load/?output_format=md#return)󠁿

 true|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) True
if loaded successfully; [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/load/?output_format=md#source)󠁿

    ```php
    public function load() {
    	if ( $this->image ) {
    		return true;
    	}

    	if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) {
    		return new WP_Error( 'error_loading_image', __( 'File does not exist?' ), $this->file );
    	}

    	// Set artificially high because GD uses uncompressed images in memory.
    	wp_raise_memory_limit( 'image' );

    	$file_contents = @file_get_contents( $this->file );

    	if ( ! $file_contents ) {
    		return new WP_Error( 'error_loading_image', __( 'File does not exist?' ), $this->file );
    	}

    	// Handle WebP and AVIF mime types explicitly, falling back to imagecreatefromstring.
    	if (
    		function_exists( 'imagecreatefromwebp' ) && ( 'image/webp' === wp_get_image_mime( $this->file ) )
    	) {
    		$this->image = @imagecreatefromwebp( $this->file );
    	} elseif (
    		function_exists( 'imagecreatefromavif' ) && ( 'image/avif' === wp_get_image_mime( $this->file ) )
    	) {
    		$this->image = @imagecreatefromavif( $this->file );
    	} else {
    		$this->image = @imagecreatefromstring( $file_contents );
    	}

    	if ( ! is_gd_image( $this->image ) ) {
    		return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file );
    	}

    	$size = wp_getimagesize( $this->file );

    	if ( ! $size ) {
    		return new WP_Error( 'invalid_image', __( 'Could not read image size.' ), $this->file );
    	}

    	if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) {
    		imagealphablending( $this->image, false );
    		imagesavealpha( $this->image, true );
    	}

    	$this->update_size( $size[0], $size[1] );
    	$this->mime_type = $size['mime'];

    	return $this->set_quality();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-image-editor-gd.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-image-editor-gd.php#L90)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-image-editor-gd.php#L90-L140)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/load/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Image_Editor_GD::set_quality()](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/set_quality/)`wp-includes/class-wp-image-editor-gd.php` |

Sets Image Compression quality on a 1-100% scale. Handles WebP lossless images.

  | 
| [wp_getimagesize()](https://developer.wordpress.org/reference/functions/wp_getimagesize/)`wp-includes/media.php` |

Allows PHP’s getimagesize() to be debuggable when necessary.

  | 
| [is_gd_image()](https://developer.wordpress.org/reference/functions/is_gd_image/)`wp-includes/media.php` |

Determines whether the value is an acceptable type for GD image functions.

  | 
| [wp_get_image_mime()](https://developer.wordpress.org/reference/functions/wp_get_image_mime/)`wp-includes/functions.php` |

Returns the real mime type of an image file.

  | 
| [wp_raise_memory_limit()](https://developer.wordpress.org/reference/functions/wp_raise_memory_limit/)`wp-includes/functions.php` |

Attempts to raise the PHP memory limit for memory intensive processes.

  | 
| [WP_Image_Editor_GD::update_size()](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/update_size/)`wp-includes/class-wp-image-editor-gd.php` |

Sets or updates current image size.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 3 more](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/load/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/load/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/load/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_image_editor_gd%2Fload%2F)
before being able to contribute a note or feedback.