app/Media.php
public function firstImageFile(): ?MediaFile
    {
        foreach ($this->mediaFiles() as $media_file) {
            if ($media_file->isImage()) {
                return $media_file;
            }
        }

        return null;
    }
public function firstImageFile(): ?MediaFile
    {
        foreach ($this->mediaFiles() as $media_file) {
            if ($media_file->isImage()) {
                return $media_file;
            }
        }

        return null;
    }
public function firstImageFile ( ) : ? MediaFile { foreach ( $ this -> mediaFiles ( ) as $ media_file ) { if ( $ media_file -> isImage ( ) ) { return $ media_file ; } } return null ; }
Get the first media file that contains an image.

@return MediaFile|null
Get the first media file that contains an image .