Advertisements

wp_load_image

Definition:
function wp_load_image( $file ) {}

Load an image from a string, if PHP supports it.

Parameters

  • string $file: Filename of the image to load.

Return values

returns:The resulting image resource on success, Error string on failure.

Defined filters

  • image_memory_limit
    apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT )

Source code

function wp_load_image( $file ) {

	if ( is_numeric( $file ) )

		$file = get_attached_file( $file );



	if ( ! file_exists( $file ) )

		return sprintf(__('File “%s” doesn’t exist?'), $file);



	if ( ! function_exists('imagecreatefromstring') )

		return __('The GD image library is not installed.');



	// Set artificially high because GD uses uncompressed images in memory

	@ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );

	$image = imagecreatefromstring( file_get_contents( $file ) );



	if ( !is_resource( $image ) )

		return sprintf(__('File “%s” is not an image.'), $file);



	return $image;

}

3875

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: