Automattic / Automattic/VIP-Coding-Standards
Sniff for getimagesize()
- Dominant language
- PHP
- Stars
- 261
- Forks
- 44
- Avg merge
- 19m
- Merged PRs (30d)
- 1
Description
## What problem would the enhancement address for VIP?
`getimagesize()` holds up the PHP process downloading the entire image to just read its file size.
## Describe the solution you'd like
Most images in WPs Media Library have width and height attributes already (like from `wp_get_attachment_metadata()`) & that existing data should be used instead.
If the image is external and not in WordPress' media library, perhapes:
* a VIP helper function could be created [to download only first few bytes of image](https://www.php.net/manual/en/function.getimagesize.php#88793)
* don't use this function, or do image sizing w/ JS or CSS instead
## What code should be reported as a violation?
```php
$size = getimagesize( $image_url );
list($width, $height) = getimagesize( $image_url );
//etc.
```
Contributor guide
Assessment
This issue has not been assessed yet.