Images
The media library, the sizes an image field declares, and printing an image as a picture.
Images live in one media library for the whole installation. A field holds an image's id, and declares the sizes it is printed at. Every one of those sizes is written as AVIF and WebP when a file is uploaded, as far as your GD writes them. A size added later is written by mainstay:media:reprocess, which queues the missing copies of every image.
Declare the sizes
#[Image(sizes: ['cover' => [1600, 900], 'card' => [640]])]
public ?Media $cover;
A width and a height crop to that shape around the image's focal point; a width alone scales. Neither enlarges an image smaller than the size. The property is always nullable, since null is no image chosen; required: true is what makes a write need one.
Print one
{{ $entry->cover?->picture('cover') }}
picture() prints a <picture> with the AVIF as a source and the WebP as the <img>, offering only the formats the image was written in, with the alt text and the copy's real width and height, lazy unless you pass other attributes. For your own markup there are url('card'), url('card', 'avif'), null for a format the image was not written in, width('card') and height('card').
Upload from code
$cover = Mainstay::media()->upload(
database_path('seeders/images/harbour.png'),
alt: ['en' => 'A harbour at dusk, two boats moored'],
overrideAccess: true,
);
Mainstay::update(Article::class, $id, ['cover' => $cover->id], overrideAccess: true);
Alt text names every content locale; an empty string marks an image as decorative, and a language left out is refused. The focal point is two percentages, across and down, [50, 50] by default, and is set in the library's screen too.
An image is recognised by its bytes, not its name: JPEG, PNG, GIF and WebP. SVG is refused, since an SVG can carry script.
What is kept where
Each file is held once, by the hash of its bytes, so uploading the same file twice is refused, naming the image that holds it. The copies go to the public disk, MAINSTAY_MEDIA_DISK, and are linked to as plain files named from everything they are made of, so nothing ever needs invalidating. The original goes to a private disk, MAINSTAY_MEDIA_ORIGINALS, and is never served: it still carries the camera's EXIF, GPS included, which the copies are written without.
Adding a size later
A size added to a field reaches images uploaded before it with one command, which queues a job per image writing the copies that are missing:
php artisan mainstay:media:reprocess
Missing images
An image in the trash, or gone, still reads as a Media, marked missing and holding its id. It prints nothing and links nowhere, and once it is back every place it was used shows it again.