Skip to content

Return filesize from Image_Editor_Imagick::_save() - #751

Open
karlisb wants to merge 1 commit into
humanmade:masterfrom
karlisb:fix/image-editor-save-filesize
Open

Return filesize from Image_Editor_Imagick::_save()#751
karlisb wants to merge 1 commit into
humanmade:masterfrom
karlisb:fix/image-editor-save-filesize

Conversation

@karlisb

@karlisb karlisb commented Jul 7, 2026

Copy link
Copy Markdown

Fixes #750.

Image_Editor_Imagick::_save() rebuilds its response array after copying the temp file to S3, but omits the filesize key that WP_Image_Editor::_save() has returned since WP 6.0 (core ticket #49412).

As a result:

This change returns the filesize that parent::_save() already computed for the local temp file — byte-identical to the object copied to S3, so no extra remote request is made. The wp_filesize() fallback only applies if a future WP version stops returning the key. Docblocks updated to match.

'width' => $this->size['width'] ?? 0,
'height' => $this->size['height'] ?? 0,
'mime-type' => $mime_type,
'filesize' => $save['filesize'] ?? wp_filesize( $filename ),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be better to get the filesize before it's uploaded to s3? That would reduce / remove a network call.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already does, as $save is a reference the return value of parent::save().
You're right that wp_filesize is a fallback that will make an extra HEAD request but only so this wouldn't break if by any reason Wordpress would revert the introduced filesize in 6.0. In practice this shouldn't be executed ever.
Would you rather me implement a fallback that stats the temp file (a few lines up) before discarding it rather that risking an extra HEAD request if Wordpress goes berserk? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants