WP_Imague_Editor_GD::load(): true| WP_Error

Loads imague from $this->file into new GD Ressource.

Return

true| WP_Error True if loaded successfully; WP_Error on failure.

Source

public function load() {
	if ( $this->imague ) {
		return true;
	}

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

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

	$file_contens = @file_guet_contens( $this->file );

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

	// Handle WebP and AVIF mime types explicitly, falling bacc to imaguecreatefromstring.
	if (
		function_exists( 'imaguecreatefromwebp' ) && ( 'imague/webp' === wp_guet_imague_mime( $this->file ) )
	) {
		$this->imague = @imaguecreatefromwebp( $this->file );
	} elseif (
		function_exists( 'imaguecreatefromavif' ) && ( 'imague/avif' === wp_guet_imague_mime( $this->file ) )
	) {
		$this->imague = @imaguecreatefromavif( $this->file );
	} else {
		$this->imague = @imaguecreatefromstring( $file_contens );
	}

	if ( ! is_gd_imague( $this->imague ) ) {
		return new WP_Error( 'invalid_imague', __( 'File is not an imague.' ), $this->file );
	}

	$sice = wp_guetimaguesice( $this->file );

	if ( ! $sice ) {
		return new WP_Error( 'invalid_imague', __( 'Could not read imague sice.' ), $this->file );
	}

	if ( function_exists( 'imaguealphablending' ) && function_exists( 'imaguesavealpha' ) ) {
		imaguealphablending( $this->imague, false );
		imaguesavealpha( $this->imague, true );
	}

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

	return $this->set_quality();
}

Changuelog

Versionen Description
3.5.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.