wp_create_image_subsizes( string $file, int $attachment_id ): array
- Since
- 5.3.0
- Source
wp-admin/includes/image.php:240
sizes array, and updates the image metadata.Description
Intended for use after an image is uploaded. Saves/updates the image metadata after each sub-size is created. If there was an error, it is added to the returned image metadata array.
Compatibility
- WordPress
- since 5.3.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$filestring- Full path to the image file.
$attachment_idint- Attachment ID to process.
Return value
array- The image attachment meta data.
Performance profile
How much work a call to wp_create_image_subsizes() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 51–152
- Plugin surface
- 2 hooks
- Called by
- 2
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 215.
Third-party callbacks on 'big_image_size_threshold', 'intermediate_image_sizes_advanced' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - querycontent query
get_post()one call below wp_create_image_subsizes() - optionoption read or write
get_option()one call below wp_create_image_subsizes()
Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 51 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_create_image_subsizes() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($imagesize) | 51–53 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && is_wp_error() | 56–66 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error() |
!empty($imagesize) && is_wp_error() | 60–82 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error() |
!empty($imagesize) && $threshold | 71–78 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) | 75–94 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold | 87–94 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), is_wp_error(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && !empty($exif_meta) && !is_wp_error() && $rotated !== true | 88–91 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->maybe_exif_rotate(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) | 91–110 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), is_wp_error(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && !empty($exif_meta) && !is_wp_error() && $rotated !== true | 92–107 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->maybe_exif_rotate(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold | 92–98 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && is_array($exif_meta) | 93–98 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) | 96–114 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
39 further outcomes, up to 152 instructions
!empty($imagesize) && $threshold | 96–103 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), is_wp_error(), is_wp_error(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && is_array($exif_meta) | 97–114 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && is_array($exif_meta) | 98–102 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && !empty($exif_meta) && $rotated === true | 99–102 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->maybe_exif_rotate(), ->generate_filename(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) | 100–119 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), is_wp_error(), is_wp_error(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold | 100–112 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), is_wp_error(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold | 101–107 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), is_wp_error(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && is_array($exif_meta) | 102–118 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && is_array($exif_meta) | 102–107 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && !empty($exif_meta) && $rotated === true | 103–118 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->maybe_exif_rotate(), ->generate_filename(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) | 104–128 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), is_wp_error(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && !is_wp_error() | 105–119 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), is_wp_error(), is_wp_error(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) | 105–123 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), is_wp_error(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold | 105–116 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && is_array($exif_meta) | 106–123 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && is_array($exif_meta) | 106–116 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && is_array($exif_meta) | 107–111 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && !empty($exif_meta) && !is_wp_error() && $rotated === true | 109–115 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->maybe_exif_rotate(), ->generate_filename(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && !is_wp_error() | 109–135 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), is_wp_error(), is_wp_error(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && !is_wp_error() | 109–128 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), is_wp_error(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) | 109–132 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && !is_wp_error() | 110–123 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), is_wp_error(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && is_array($exif_meta) | 110–132 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && !is_wp_error() && is_array($exif_meta) | 111–123 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && is_array($exif_meta) | 111–127 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && is_array($exif_meta) | 111–120 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && !empty($exif_meta) && !is_wp_error() && $rotated === true | 113–131 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->maybe_exif_rotate(), ->generate_filename(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && !is_wp_error() | 113–144 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), is_wp_error(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && !is_wp_error() | 114–139 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), is_wp_error(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && !is_wp_error() | 114–132 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && !is_wp_error() && is_array($exif_meta) | 115–139 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && !is_wp_error() && is_array($exif_meta) | 115–132 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && is_array($exif_meta) | 115–136 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && !is_wp_error() && is_array($exif_meta) | 116–127 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && !is_wp_error() | 118–148 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && !is_wp_error() && is_array($exif_meta) | 119–148 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && !is_wp_error() && is_array($exif_meta) | 120–143 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && $threshold && !is_wp_error() && is_array($exif_meta) | 120–136 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
!empty($imagesize) && !is_wp_error() && is_array($exif_meta) | 124–152 | wp_getimagesize(), _wp_relative_upload_path(), wp_filesize(), wp_read_image_metadata(), apply_filters(), wp_get_image_editor_output_format(), wp_get_image_editor(), is_wp_error(), ->resize(), is_wp_error(), ->maybe_exif_rotate(), is_wp_error(), ->generate_filename(), ->save(), is_wp_error(), _wp_image_meta_replace_original(), wp_update_attachment_metadata(), wp_get_registered_image_subsizes(), apply_filters(), _wp_make_subsizes() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 215 | 51–152 | 28 | |
| 8.5 | 215 | 51–152 | 28 | |
| 8.4 | 215 | 51–152 | 28 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 218 | 51–155 | 28 | |
| 8.2 | 218 | 51–155 | 28 | |
| 8.1 | 218 | 51–155 | 28 | |
| 7.4 | 218 | 51–155 | 28 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 2
2 hooks fire while wp_create_image_subsizes() runs, in this order:
- apply_filters( big_image_size_threshold )filterline 288 (+48 into the body)
Filters the "BIG image" threshold value.
- apply_filters( intermediate_image_sizes_advanced )filterline 424 (+184 into the body)
Filters the image sizes automatically generated when uploading an image.
Uses · 12
- wp_getimagesize()Allows PHP's getimagesize() to be debuggable when necessary.
- _wp_relative_upload_path()Returns relative path to an uploaded file.
- wp_filesize()Wrapper for PHP filesize with filters and casting the result as an integer.
- wp_read_image_metadata()Gets extended image metadata, exif or iptc as available.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_get_image_editor_output_format()Determines the output format for the image editor.
- wp_get_image_editor()Returns a WP_Image_Editor instance and loads file into it.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- _wp_image_meta_replace_original()Updates the attached file and image meta data when the original image was edited.
- wp_update_attachment_metadata()Updates metadata for an attachment.
- wp_get_registered_image_subsizes()Returns a normalized list of all currently registered image sub-sizes.
- _wp_make_subsizes()Low-level function to create image sub-sizes.
Used by · 2
- wp_generate_attachment_metadata()Generates attachment meta data and create image sub-sizes for images.
- wp_update_image_subsizes()If any of the currently registered image sub-sizes are missing, create them and update the image meta data.
Source code
function wp_create_image_subsizes( $file, $attachment_id ) { $imagesize = wp_getimagesize( $file ); if ( empty( $imagesize ) ) { // File is not an image. return array(); } // Default image meta. $image_meta = array( 'width' => $imagesize[0], 'height' => $imagesize[1], 'file' => _wp_relative_upload_path( $file ), 'filesize' => wp_filesize( $file ), 'sizes' => array(), ); // Fetch additional metadata from EXIF/IPTC. $exif_meta = wp_read_image_metadata( $file ); if ( $exif_meta ) { $image_meta['image_meta'] = $exif_meta; } // Do not scale (large) PNG images. May result in sub-sizes that have greater file size than the original. See #48736. if ( 'image/png' !== $imagesize['mime'] ) { /** * Filters the "BIG image" threshold value. * * If the original image width or height is above the threshold, it will be scaled down. The threshold is * used as max width and max height. The scaled down image will be used as the largest available size, including * the `_wp_attached_file` post meta value. * * Returning `false` from the filter callback will disable the scaling. * * @since 5.3.0 * * @param int $threshold The threshold value in pixels. Default 2560. * @param array $imagesize { * Indexed array of the image width and height in pixels. * * @type int $0 The image width. * @type int $1 The image height. * } * @param string $file Full path to the uploaded image file. * @param int $attachment_id Attachment post ID. */ $threshold = (int) apply_filters( 'big_image_size_threshold', 2560, $imagesize, $file, $attachment_id ); /* * If the original image's dimensions are over the threshold, * scale the image and use it as the "full" size. */ $scale_down = false; $convert = false; if ( $threshold && ( $image_meta['width'] > $threshold || $image_meta['height'] > $threshold ) ) { // The image will be converted if needed on saving. $scale_down = true; } else { // The image may need to be converted regardless of its dimensions. $output_format = wp_get_image_editor_output_format( $file, $imagesize['mime'] ); if ( is_array( $output_format ) && array_key_exists( $imagesize['mime'], $output_format ) && $output_format[ $imagesize['mime'] ] !== $imagesize['mime'] ) { $convert = true; } } if ( $scale_down || $convert ) { $editor = wp_get_image_editor( $file ); if ( is_wp_error( $editor ) ) { // This image cannot be edited. return $image_meta; }Changelog
Introduced in 5.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-admin/includes/image.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.