Generate media assets programmatically

Hi,

I’m working on a project with a lot of images on one page. Is there a good way to generate all media assets including srcset thumbnails all at once?

Guess you mean moving them all to the media folder? You can use $file->publish() to publish files to the media folder.

In my case this did not create all thumbnail renditions:

  'thumbs' => [
    'srcsets' => [
      'default' => [
        '800w' => ['width' => 800, 'quality' => 80],
        '1024w' => ['width' => 1024, 'quality' => 80],
        '1440w' => ['width' => 1440, 'quality' => 80],
        '2048w' => ['width' => 2048, 'quality' => 80]
      ],

An, sorry, for the thumbs, you have to call save() instead of publish().

1 Like