wp_getimagesize
函数
wp_getimagesize ( $filename, $image_info = null )
- 参数
-
-
(string)
$filename
The file path.- Required: 是
-
(array)
$image_info
Optional. Extended image information (passed by reference).- Required: 否
- Default: null
-
(string)
- 返回值
-
- (array|false) Array of image information or false on failure.
- 定义位置
-
-
wp-includes/media.php
, line 5280
-
wp-includes/media.php
- 引入
- 5.7.0
- 弃用
- –
Allows PHP’s getimagesize() to be debuggable when necessary.
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 { /* * 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 $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; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。