Make WordPress Core

Opened 8 months ago

Last modified 11 days ago

#59684 assigned defect (bug)

'filesize' metadata not updated after resizing media

Reported by: vertisoft's profile vertisoft Owned by: antpb's profile antpb
Milestone: 6.6 Priority: normal
Severity: minor Version: 6.3.3
Component: Media Keywords: has-testing-info has-patch
Focuses: Cc:


It seems like WordPress does not update the 'filesize' metadata after an image is modified through the media library. The details panel in the media library displays the original file size instead of the 'new' file size.


  • WordPress: 6.3.3-alpha-56924
  • PHP: 8.2.10
  • Server: Apache
  • Database: mysqli (Server: 5.7.31 / Client: mysqlnd 8.2.10)
  • Browser: Chrome (Windows 10/11)
  • MU-Plugins: None activated
  • Plugins:
    • WordPress Beta Tester 3.5.4

The following optional modules are not currently installed on our server:

  • exif
  • fileinfo
  • imagick

Steps to Reproduce

  1. Upload a new image in the media library
  2. Note the file size (ie. 22 KB)
  3. Resize the image by clicking on 'Edit Image', then 'Scale Image' (in my test case, I resized the image from 1920x1080 to 200x113)
  4. Click 'Update'
  5. The 'Dimensions' field is correctly updated, but 'File size' remains the same (22 KB)

Expected Results

The 'File size' should display the new file size (ie. 3.3 KB)

Actual Results

The 'File size' field displays the size of the original image, before it was resized.

Here is the value of the '_wp_attachment_metadata' field in the database after the media is resized:


The "filesize" metadata has the value '22990' instead of '3033'.

Attachments (3)

Test.png (22.5 KB) - added by vertisoft 8 months ago.
Test image
Before.jpg (138.0 KB) - added by vertisoft 8 months ago.
Before resizing
After.jpg (165.7 KB) - added by vertisoft 8 months ago.
After resizing

Download all attachments as: .zip

Change History (12)

8 months ago

Test image

8 months ago

Before resizing

8 months ago

After resizing

This ticket was mentioned in Slack in #core-test by ankit-k-gupta. View the logs.

8 months ago

#2 @Ankit K Gupta
8 months ago

  • Keywords has-testing-info needs-patch added

This ticket was mentioned in Slack in #core-media by antpb. View the logs.

2 months ago

#4 @antpb
2 months ago

  • Milestone changed from Awaiting Review to 6.6

this was mentioned in the recent Media component meeting and we agreed to move it to 6.6. Should be a simple write to update the metadata on resize. Keeping it top of mind. :)

This ticket was mentioned in PR #6406 on WordPress/wordpress-develop by @pls78.

2 months ago

  • Keywords has-patch added; needs-patch removed

### What
This PR fixes the wrong file size displayed in the medial library when a user resizes an image. At the same time, if the user decides to revert the changes made to the image, this PR makes possible to revert to the original file size.

### Why
This PR solves the issue described in the following Trac ticket:

### How

  • In the wp_save_image function I collect the array returned by wp_save_image_file and add it to the attachment metadata array as $meta['filesize']
    • This allows to show the correct file size when the image is scaled
  • Before doing this I save the original filesize in in the $backup_sizes array
    • This allows to retrieve the original file size in case the user reverts the changes made to the image size
  • In the wp_restore_image function I then read back from $backup_sizes the original file size and restore it when the user reverts back to the original size

This ticket was mentioned in Slack in #core-media by antpb. View the logs.

3 weeks ago

#7 @antpb
3 weeks ago

  • Owner set to antpb
  • Status changed from new to assigned

#8 @rajinsharwar
12 days ago

Test Report

This report validates that the indicated patch addresses the issue.

Patch tested:

### Environment

  • WordPress: 6.6-beta2-58392-src
  • PHP: 8.3.0
  • Server: NGINX
  • Browser: Chrome

Actual Results

  • ✅ The file size is now showing smaller when resized to a smaller resolution.

Before Patch

After Patch

#9 @gauravsingh7
11 days ago

Tested this patch. Seems to be working fine on my end.
The image size is getting updated after downscaling it.

Note: See TracTickets for help on using tickets.