1

I use a shell command to look for all uploaded JPEG files above 500 K.B. (originals) and do JPEG compression on them. They get smaller in size, but Drupal still shows the originally uploaded file size. How to force a recalculation and update the database accordingly after JPEG optimization?

1

In Drupal 7 managed files have their filesize property updated upon saving in the file_save() function. So you can just load/save each resized files to have it updated in the DB accordingly.

//@TODO: Get list of $fids corresponding to resized-files
foreach ($fids as $fid) {
  $file = file_load($fid);
  // $file->filesize reflects old size
  file_save($file);
  // $file->filesize now reflects new size
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.