wp_getimagesize

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

WordPress Version: 6.5

/**
 * Allows PHP's getimagesize() to be debuggable when necessary.
 *
 * @since 5.7.0
 * @since 5.8.0 Added support for WebP images.
 * @since 6.5.0 Added support for AVIF images.
 *
 * @param string $filename   The file path.
 * @param array  $image_info Optional. Extended image information (passed by reference).
 * @return array|false Array of image information or false on failure.
 */
function wp_getimagesize($filename, array &$image_info = null)
{
    // Don't silence errors when in debug mode, unless running unit tests.
    if (defined('WP_DEBUG') && WP_DEBUG && !defined('WP_RUN_CORE_TESTS')) {
        if (2 === func_num_args()) {
            $info = getimagesize($filename, $image_info);
        } else {
            $info = getimagesize($filename);
        }
    } else if (2 === func_num_args()) {
        $info = @getimagesize($filename, $image_info);
    } else {
        $info = @getimagesize($filename);
    }
    if (!empty($info) && !(empty($info[0]) && empty($info[1]))) {
        return $info;
    }
    /*
     * For PHP versions that don't support WebP images,
     * extract the image size info from the file headers.
     */
    if ('image/webp' === wp_get_image_mime($filename)) {
        $webp_info = wp_get_webp_info($filename);
        $width = $webp_info['width'];
        $height = $webp_info['height'];
        // Mimic the native return format.
        if ($width && $height) {
            return array($width, $height, IMAGETYPE_WEBP, sprintf('width="%d" height="%d"', $width, $height), 'mime' => 'image/webp');
        }
    }
    // For PHP versions that don't support AVIF images, extract the image size info from the file headers.
    if ('image/avif' === wp_get_image_mime($filename)) {
        $avif_info = wp_get_avif_info($filename);
        $width = $avif_info['width'];
        $height = $avif_info['height'];
        // Mimic the native return format.
        if ($width && $height) {
            return array($width, $height, IMAGETYPE_AVIF, sprintf('width="%d" height="%d"', $width, $height), 'mime' => 'image/avif');
        }
    }
    // The image could not be parsed.
    return false;
}

WordPress Version: 6.4

/**
 * Allows PHP's getimagesize() to be debuggable when necessary.
 *
 * @since 5.7.0
 * @since 5.8.0 Added support for WebP images.
 *
 * @param string $filename   The file path.
 * @param array  $image_info Optional. Extended image information (passed by reference).
 * @return array|false Array of image information or false on failure.
 */
function wp_getimagesize($filename, array &$image_info = null)
{
    // Don't silence errors when in debug mode, unless running unit tests.
    if (defined('WP_DEBUG') && WP_DEBUG && !defined('WP_RUN_CORE_TESTS')) {
        if (2 === func_num_args()) {
            $info = getimagesize($filename, $image_info);
        } else {
            $info = getimagesize($filename);
        }
    } else if (2 === func_num_args()) {
        $info = @getimagesize($filename, $image_info);
    } else {
        $info = @getimagesize($filename);
    }
    if (false !== $info) {
        return $info;
    }
    /*
     * For PHP versions that don't support WebP images,
     * extract the image size info from the file headers.
     */
    if ('image/webp' === wp_get_image_mime($filename)) {
        $webp_info = wp_get_webp_info($filename);
        $width = $webp_info['width'];
        $height = $webp_info['height'];
        // Mimic the native return format.
        if ($width && $height) {
            return array($width, $height, IMAGETYPE_WEBP, sprintf('width="%d" height="%d"', $width, $height), 'mime' => 'image/webp');
        }
    }
    // The image could not be parsed.
    return false;
}

WordPress Version: 6.3

/**
 * Allows PHP's getimagesize() to be debuggable when necessary.
 *
 * @since 5.7.0
 * @since 5.8.0 Added support for WebP images.
 *
 * @param string $filename   The file path.
 * @param array  $image_info Optional. Extended image information (passed by reference).
 * @return array|false Array of image information or false on failure.
 */
function wp_getimagesize($filename, array &$image_info = null)
{
    // Don't silence errors when in debug mode, unless running unit tests.
    if (defined('WP_DEBUG') && WP_DEBUG && !defined('WP_RUN_CORE_TESTS')) {
        if (2 === func_num_args()) {
            $info = getimagesize($filename, $image_info);
        } else {
            $info = getimagesize($filename);
        }
    } else if (2 === func_num_args()) {
        // phpcs:ignore WordPress.PHP.NoSilencedErrors
        $info = @getimagesize($filename, $image_info);
    } else {
        // phpcs:ignore WordPress.PHP.NoSilencedErrors
        $info = @getimagesize($filename);
    }
    if (false !== $info) {
        return $info;
    }
    /*
     * For PHP versions that don't support WebP images,
     * extract the image size info from the file headers.
     */
    if ('image/webp' === wp_get_image_mime($filename)) {
        $webp_info = wp_get_webp_info($filename);
        $width = $webp_info['width'];
        $height = $webp_info['height'];
        // Mimic the native return format.
        if ($width && $height) {
            return array($width, $height, IMAGETYPE_WEBP, sprintf('width="%d" height="%d"', $width, $height), 'mime' => 'image/webp');
        }
    }
    // The image could not be parsed.
    return false;
}

WordPress Version: 5.9

/**
 * Allows PHP's getimagesize() to be debuggable when necessary.
 *
 * @since 5.7.0
 * @since 5.8.0 Added support for WebP images.
 *
 * @param string $filename   The file path.
 * @param array  $image_info Optional. Extended image information (passed by reference).
 * @return array|false Array of image information or false on failure.
 */
function wp_getimagesize($filename, array &$image_info = null)
{
    // Don't silence errors when in debug mode, unless running unit tests.
    if (defined('WP_DEBUG') && WP_DEBUG && !defined('WP_RUN_CORE_TESTS')) {
        if (2 === func_num_args()) {
            $info = getimagesize($filename, $image_info);
        } else {
            $info = getimagesize($filename);
        }
    } else if (2 === func_num_args()) {
        // phpcs:ignore WordPress.PHP.NoSilencedErrors
        $info = @getimagesize($filename, $image_info);
    } else {
        // phpcs:ignore WordPress.PHP.NoSilencedErrors
        $info = @getimagesize($filename);
    }
    if (false !== $info) {
        return $info;
    }
    // For PHP versions that don't support WebP images,
    // extract the image size info from the file headers.
    if ('image/webp' === wp_get_image_mime($filename)) {
        $webp_info = wp_get_webp_info($filename);
        $width = $webp_info['width'];
        $height = $webp_info['height'];
        // Mimic the native return format.
        if ($width && $height) {
            return array($width, $height, IMAGETYPE_WEBP, sprintf('width="%d" height="%d"', $width, $height), 'mime' => 'image/webp');
        }
    }
    // The image could not be parsed.
    return false;
}

WordPress Version: 5.8

/**
 * Allows PHP's getimagesize() to be debuggable when necessary.
 *
 * @since 5.7.0
 * @since 5.8.0 Added support for WebP images.
 *
 * @param string $filename   The file path.
 * @param array  $image_info Optional. Extended image information (passed by reference).
 * @return array|false Array of image information or false on failure.
 */
function wp_getimagesize($filename, array &$image_info = null)
{
    // Don't silence errors when in debug mode, unless running unit tests.
    if (defined('WP_DEBUG') && WP_DEBUG && !defined('WP_RUN_CORE_TESTS')) {
        if (2 === func_num_args()) {
            $info = getimagesize($filename, $image_info);
        } else {
            $info = getimagesize($filename);
        }
    } else if (2 === func_num_args()) {
        // phpcs:ignore WordPress.PHP.NoSilencedErrors
        $info = @getimagesize($filename, $image_info);
    } else {
        // phpcs:ignore WordPress.PHP.NoSilencedErrors
        $info = @getimagesize($filename);
    }
    if (false !== $info) {
        return $info;
    }
    // For PHP versions that don't support WebP images,
    // extract the image size info from the file headers.
    if ('image/webp' === wp_get_image_mime($filename)) {
        $webp_info = wp_get_webp_info($filename);
        $width = $webp_info['width'];
        $height = $webp_info['height'];
        // Mimic the native return format.
        if ($width && $height) {
            return array(
                $width,
                $height,
                IMAGETYPE_WEBP,
                // phpcs:ignore PHPCompatibility.Constants.NewConstants.imagetype_webpFound
                sprintf('width="%d" height="%d"', $width, $height),
                'mime' => 'image/webp',
            );
        }
    }
    // The image could not be parsed.
    return false;
}

WordPress Version: 7.1

/**
 * Allows PHP's getimagesize() to be debuggable when necessary.
 *
 * @since 5.7.0
 *
 * @param string $filename   The file path.
 * @param array  $image_info Optional. Extended image information (passed by reference).
 * @return array|false Array of image information or false on failure.
 */
function wp_getimagesize($filename, array &$image_info = null)
{
    if (!defined('WP_RUN_CORE_TESTS') && defined('WP_DEBUG') && WP_DEBUG) {
        if (2 === func_num_args()) {
            return getimagesize($filename, $image_info);
        } else {
            return getimagesize($filename);
        }
    }
    /*
     * Silencing notice and warning is intentional.
     *
     * getimagesize() has a tendency to generate errors, such as
     * "corrupt JPEG data: 7191 extraneous bytes before marker",
     * even when it's able to provide image size information.
     *
     * See https://core.trac.wordpress.org/ticket/42480
     */
    if (2 === func_num_args()) {
        // phpcs:ignore WordPress.PHP.NoSilencedErrors
        return @getimagesize($filename, $image_info);
    } else {
        // phpcs:ignore WordPress.PHP.NoSilencedErrors
        return @getimagesize($filename);
    }
}

WordPress Version: 5.7

/**
 * Allows PHP's getimagesize() to be debuggable when necessary.
 *
 * @since 5.7.0
 *
 * @param string $filename  The file path.
 * @param array  $imageinfo Extended image information, passed by reference.
 * @return array|false Array of image information or false on failure.
 */
function wp_getimagesize($filename, &$imageinfo = array())
{
    if (!defined('WP_RUN_CORE_TESTS') && defined('WP_DEBUG') && WP_DEBUG) {
        return getimagesize($filename, $imageinfo);
    }
    /*
     * Silencing notice and warning is intentional.
     *
     * getimagesize() has a tendency to generate errors, such as
     * "corrupt JPEG data: 7191 extraneous bytes before marker",
     * even when it's able to provide image size information.
     *
     * See https://core.trac.wordpress.org/ticket/42480
     *
     * phpcs:ignore WordPress.PHP.NoSilencedErrors
     */
    return @getimagesize($filename, $imageinfo);
}