FoPost LogoFoPost Docs
Core Concepts

Media Handling

Working with Media for images, videos, and documents.

Media Handling

Media

A single media attachment - image, video, audio, or document.

use OwlStack\Media;

// Quick factory methods
$image = Media::image('/path/to/photo.jpg');
$video = Media::video('/path/to/clip.mp4');

// Full constructor
$image = Media::create(
    path: '/path/to/photo.jpg',
    mimeType: 'image/jpeg',
    altText: 'A sunset over the ocean',
);

Type checks

$image->isImage();    // true
$image->isVideo();    // false
$image->isAudio();    // false
$image->isDocument(); // false

MediaCollection

An immutable, typed collection. Adding items returns a new instance.

use OwlStack\MediaCollection;

$collection = new MediaCollection();
$collection = $collection->add($image1);
$collection = $collection->add($image2);
$collection = $collection->add($video);

$collection->count();    // 3
$collection->first();    // $image1
$collection->images();   // MediaCollection with $image1, $image2
$collection->videos();   // MediaCollection with $video
$collection->isEmpty();  // false
$collection->all();      // Media[]

Attaching to a Post

use OwlStack\Post;
use OwlStack\Media;
use OwlStack\MediaCollection;

$post = Post::create('Check out these photos!')
    ->withMediaCollection(new MediaCollection([
        Media::image('/path/to/img1.jpg'),
        Media::image('/path/to/img2.jpg'),
    ]));

Platform media constraints

Each platform has different media requirements. OwlStack handles validation and processing on the server:

PlatformMax MediaSupported Types
Telegram10JPEG, PNG, GIF, MP4, OGG
Twitter/X4JPEG, PNG, GIF, MP4
Facebook1JPEG, PNG, GIF, BMP, MP4, AVI
LinkedIn1JPEG, PNG, GIF
Discord10JPEG, PNG, GIF, WebP, MP4
Instagram10JPEG, MP4
Pinterest1JPEG, PNG, GIF, WebP, MP4
Reddit1JPEG, PNG, GIF

When you publish with media, OwlStack's cloud:

  • Validates the file type against the target platform
  • Resizes images if they exceed platform limits
  • Converts formats as needed (e.g., PNG to JPEG for Instagram)
  • Uploads the media to the platform's API

On this page