Skip to content

5-Minute Quickstart

This walkthrough covers the four most common tasks with $this->wire()->media using an editorial yacht charter site (“Aegean Voyages”) as the example.

  1. Upload a public asset with tags and localized metadata

    <?php
    declare(strict_types=1);
    namespace ProcessWire;
    $media = $this->wire()->media;
    $asset = $media->upload('/tmp/gocek-sunset-hero.jpg', [
    'title' => 'Gocek 12 Islands Sunset',
    'alt' => 'Sailing yacht anchored at sunset across Gocek islands',
    'tags' => ['hero', 'gocek', 'sunset'],
    ]);
  2. Resize, extract a color palette, and render a responsive <picture>

    <?php
    declare(strict_types=1);
    namespace ProcessWire;
    $lang = $this->wire()->languages ? $this->wire()->user->language : null;
    // ProcessWire-familiar resize/crop cached in entries_tbl_media_crops
    $heroCrop = $asset->size(1600, 900, [
    'format' => 'webp',
    'quality' => 85,
    'sharpening' => 'soft',
    ]);
    // Extract a 6-color palette for UI accents
    $palette = $asset->palette(6);
    // Render full responsive <picture> with LCP fetchpriority="high" and WebP source
    echo $asset->render(1600, 900, [
    'isFirst' => true,
    'alt' => $asset->alt($lang),
    'class' => 'hero-img',
    'webpAdd' => true,
    ]);
  3. Store a confidential module file in a Private Vault

    <?php
    declare(strict_types=1);
    namespace ProcessWire;
    $invoice = $media->uploadPrivate('commerce', '/tmp/charter-invoice-42.pdf', [
    'title' => 'Charter Invoice #42',
    'custom_meta' => ['user_id' => $this->wire()->user->id],
    ]);
    // Mint a 5-minute single-use signed download URL
    $signedUrl = $invoice->signedUrl(300, ['singleUse' => true]);
  4. Query ProcessWire pages referencing Media assets

    Add a FieldtypeMedia field (for example hero_media) to a template, attach assets from the library, and query with standard ProcessWire selectors:

    <?php
    declare(strict_types=1);
    namespace ProcessWire;
    $heroPages = $this->wire()->pages->find('hero_media.kind=image, hero_media.tags*=hero, limit=25');

Next steps