Media folder grows huge over the time

So found this thread: Programmatically generate image file in media folder after upload - #2 by texnixe

Which pointed me to necessary direction - $image->publish() does the job for copying images to /media folder, BUT somehow it does not work if I generate thumbnails… currently don’t understand what Im missing.

My current code looks like this:

$files = $item->content()->get('files')->toFiles();

foreach($files as $image) {
  $thumb = $image->thumb([
      'width'   => 100,
      'height'  => 100,
      'quality' => 70,
      'crop' => true
  ]);
  $thumbUrl = $thumb->url();
  $thumb->publish();
}