Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update the file size in file_validate_image_resolution after resizing

(cherry picked from commit 1a3d72bc67)
(cherry picked from commit 2340e939ed)
merge-requests/6800/head
catch 2024-02-26 11:52:35 +00:00
parent 98882c4f00
commit 24c236fdc7
2 changed files with 5 additions and 0 deletions

View File

@ -295,6 +295,8 @@ function file_validate_image_resolution(FileInterface $file, $maximum_dimensions
if ($image->scale($width, $height)) {
$scaling = TRUE;
$image->save();
// Update the file size now that the image has been resized.
$file->setSize($image->getFileSize());
if (!empty($width) && !empty($height)) {
$message = t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels. The new dimensions of the resized image are %new_widthx%new_height pixels.',
[

View File

@ -37,6 +37,7 @@ class LegacyValidatorTest extends FileManagedUnitTestBase {
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
$this->image->setFilename($file_system->basename($this->image->getFileUri()));
$this->image->setSize(@filesize($this->image->getFileUri()));
$this->nonImage = File::create();
$this->nonImage->setFileUri('core/assets/vendor/jquery/jquery.min.js');
@ -191,6 +192,8 @@ class LegacyValidatorTest extends FileManagedUnitTestBase {
// Verify that the image was scaled to the correct width and height.
$this->assertLessThanOrEqual(10, $image->getWidth());
$this->assertLessThanOrEqual(5, $image->getHeight());
// Verify that the file size has been updated after resizing.
$this->assertEquals($this->image->getSize(), $image->getFileSize());
// Once again, now with negative width and height to force an error.
copy('core/misc/druplicon.png', 'temporary://druplicon.png');