Search by

microweber-packages / microweber-media-thumbnail

boksiora

Standalone Laravel package for media thumbnail caching and generation. Provides the MediaThumbnail model, migration, repository, and thumbnail-serving routes.

Package info

github.com/microweber-packages/microweber-media-thumbnail

pkg:composer/microweber-packages/microweber-media-thumbnail

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-03 16:17 UTC

This package is auto-updated.

Last update: 2026-11-03 17:07:07 UTC


README

Standalone Laravel package for media thumbnail caching and on-demand generation.

Features

  • MediaThumbnail model — Stores cached thumbnail metadata (filename → image options + UUID) in a media_thumbnails table.
  • Repository — Thin caching layer over the model with find, store, remove, and prune operations.
  • Routes — pixum_img, thumbnail_img, and api/media-thumbnail/generate/{uuid} endpoints for serving thumbnails.
  • Database-agnostic — Works on SQLite, MySQL, and PostgreSQL.

Installation

composer require microweber-packages/microweber-media-thumbnail

The package auto-discovers its service provider. Publish the config and migration:

php artisan vendor:publish --tag=media-thumbnail-config
php artisan vendor:publish --tag=media-thumbnail-migrations
php artisan migrate

Dependencies

  • microweber-packages/microweber-thumbnailer — the low-level image thumbnail generator (GD-based).

Configuration

// config/media-thumbnail.php
return [
    'thumbnails_path' => env('MEDIA_THUMBNAIL_PATH', storage_path('app/public/thumbnails')),
    'thumbnails_url'  => env('MEDIA_THUMBNAIL_URL', '/storage/thumbnails'),
    'table'           => 'media_thumbnails',
];

Usage

use MicroweberPackages\MediaThumbnail\Repositories\MediaThumbnailRepository;

$repo = app(MediaThumbnailRepository::class);

// Store a new thumbnail cache entry
$model = $repo->store('tn-my-image-123', [
    'src'    => '/images/photo.jpg',
    'width'  => 300,
    'height' => 200,
]);

// Look up by filename (cache key)
$result = $repo->findByFilename('tn-my-image-123');

// Look up by UUID (for route-based generation)
$model = $repo->findByUuid($uuid);

// Remove cached entries
$repo->removeByFilename('tn-my-image-123');

// Prune old entries
$repo->pruneOlderThan(now()->subDays(90));

Testing

composer test

License

MIT