wp_load_image

The timeline below displays how wordpress function wp_load_image has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Load an image from a string, if PHP supports it.
 *
 * @since 2.1.0
 * @deprecated 3.5.0 Use wp_get_image_editor()
 * @see wp_get_image_editor()
 *
 * @param string $file Filename of the image to load.
 * @return resource|GdImage|string The resulting image resource or GdImage instance on success,
 *                                 error string on failure.
 */
function wp_load_image($file)
{
    _deprecated_function(__FUNCTION__, '3.5.0', 'wp_get_image_editor()');
    if (is_numeric($file)) {
        $file = get_attached_file($file);
    }
    if (!is_file($file)) {
        /* translators: %s: File name. */
        return sprintf(__('File “%s” does not exist?'), $file);
    }
    if (!function_exists('imagecreatefromstring')) {
        return __('The GD image library is not installed.');
    }
    // Set artificially high because GD uses uncompressed images in memory.
    wp_raise_memory_limit('image');
    $image = imagecreatefromstring(file_get_contents($file));
    if (!is_gd_image($image)) {
        /* translators: %s: File name. */
        return sprintf(__('File “%s” is not an image.'), $file);
    }
    return $image;
}

WordPress Version: 5.6

/**
 * Load an image from a string, if PHP supports it.
 *
 * @since 2.1.0
 * @deprecated 3.5.0 Use wp_get_image_editor()
 * @see wp_get_image_editor()
 *
 * @param string $file Filename of the image to load.
 * @return resource|GdImage|string The resulting image resource or GdImage instance on success,
 *                                 error string on failure.
 */
function wp_load_image($file)
{
    _deprecated_function(__FUNCTION__, '3.5.0', 'wp_get_image_editor()');
    if (is_numeric($file)) {
        $file = get_attached_file($file);
    }
    if (!is_file($file)) {
        /* translators: %s: File name. */
        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.
    wp_raise_memory_limit('image');
    $image = imagecreatefromstring(file_get_contents($file));
    if (!is_gd_image($image)) {
        /* translators: %s: File name. */
        return sprintf(__('File “%s” is not an image.'), $file);
    }
    return $image;
}

WordPress Version: 5.3

/**
 * Load an image from a string, if PHP supports it.
 *
 * @since 2.1.0
 * @deprecated 3.5.0 Use wp_get_image_editor()
 * @see wp_get_image_editor()
 *
 * @param string $file Filename of the image to load.
 * @return resource The resulting image resource on success, Error string on failure.
 */
function wp_load_image($file)
{
    _deprecated_function(__FUNCTION__, '3.5.0', 'wp_get_image_editor()');
    if (is_numeric($file)) {
        $file = get_attached_file($file);
    }
    if (!is_file($file)) {
        /* translators: %s: File name. */
        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.
    wp_raise_memory_limit('image');
    $image = imagecreatefromstring(file_get_contents($file));
    if (!is_resource($image)) {
        /* translators: %s: File name. */
        return sprintf(__('File “%s” is not an image.'), $file);
    }
    return $image;
}

WordPress Version: 4.7

/**
 * Load an image from a string, if PHP supports it.
 *
 * @since 2.1.0
 * @deprecated 3.5.0 Use wp_get_image_editor()
 * @see wp_get_image_editor()
 *
 * @param string $file Filename of the image to load.
 * @return resource The resulting image resource on success, Error string on failure.
 */
function wp_load_image($file)
{
    _deprecated_function(__FUNCTION__, '3.5.0', 'wp_get_image_editor()');
    if (is_numeric($file)) {
        $file = get_attached_file($file);
    }
    if (!is_file($file)) {
        /* translators: %s: file name */
        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.
    wp_raise_memory_limit('image');
    $image = imagecreatefromstring(file_get_contents($file));
    if (!is_resource($image)) {
        /* translators: %s: file name */
        return sprintf(__('File “%s” is not an image.'), $file);
    }
    return $image;
}

WordPress Version: 4.6

/**
 * Load an image from a string, if PHP supports it.
 *
 * @since 2.1.0
 * @deprecated 3.5.0 Use wp_get_image_editor()
 * @see wp_get_image_editor()
 *
 * @param string $file Filename of the image to load.
 * @return resource The resulting image resource on success, Error string on failure.
 */
function wp_load_image($file)
{
    _deprecated_function(__FUNCTION__, '3.5.0', 'wp_get_image_editor()');
    if (is_numeric($file)) {
        $file = get_attached_file($file);
    }
    if (!is_file($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.
    wp_raise_memory_limit('image');
    $image = imagecreatefromstring(file_get_contents($file));
    if (!is_resource($image)) {
        return sprintf(__('File “%s” is not an image.'), $file);
    }
    return $image;
}

WordPress Version: 4.4

/**
 * Load an image from a string, if PHP supports it.
 *
 * @since 2.1.0
 * @deprecated 3.5.0 Use wp_get_image_editor()
 * @see wp_get_image_editor()
 *
 * @param string $file Filename of the image to load.
 * @return resource The resulting image resource on success, Error string on failure.
 */
function wp_load_image($file)
{
    _deprecated_function(__FUNCTION__, '3.5', 'wp_get_image_editor()');
    if (is_numeric($file)) {
        $file = get_attached_file($file);
    }
    if (!is_file($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;
}

WordPress Version: 3.7

/**
 * Load an image from a string, if PHP supports it.
 *
 * @since 2.1.0
 * @deprecated 3.5.0
 * @see wp_get_image_editor()
 *
 * @param string $file Filename of the image to load.
 * @return resource The resulting image resource on success, Error string on failure.
 */
function wp_load_image($file)
{
    _deprecated_function(__FUNCTION__, '3.5', 'wp_get_image_editor()');
    if (is_numeric($file)) {
        $file = get_attached_file($file);
    }
    if (!is_file($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;
}