chocoway/moonshine-compressed-image

Compressed Image field for MoonShine

Maintainers

Package info

github.com/chocoway/moonshine-compressed-image

pkg:composer/chocoway/moonshine-compressed-image

Statistics

Installs: 20

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2026-02-21 14:33 UTC

This package is auto-updated.

Last update: 2026-03-27 02:30:42 UTC


README

A custom image field for MoonShine admin panel with built-in image compression, resizing, thumbnail generation and format conversion powered by Intervention Image v3.

Requirements

  • PHP 8.2+
  • Laravel 10|11|12
  • MoonShine 4.x
  • GD extension

Installation

composer require chocoway/moonshine-compressed-image

Usage

use Chocoway\MoonshineCompressedImage\Fields\CompressedImage;

CompressedImage::make('Photo', 'photo')
    ->width(1000)
    ->height(800)
    ->aspectRatio()
    ->format('webp')
    ->quality(80)
    ->thumb(200, 200)

Available Methods

Method Description
->width(int $width) Set max width in pixels
->height(int $height) Set max height in pixels
->aspectRatio() Keep aspect ratio when resizing
->format(string $format) Output format: jpg, png, webp, gif
->quality(int $quality) Compression quality from 1 to 100 (default: 80)
->thumb(int $width, int $height) Generate a thumbnail alongside the original

Examples

Resize with aspect ratio (recommended):

CompressedImage::make('Photo', 'photo')
    ->width(1000)
    ->aspectRatio()
    ->format('webp')
    ->quality(80)

With thumbnail:

CompressedImage::make('Photo', 'photo')
    ->width(1000)
    ->aspectRatio()
    ->format('webp')
    ->quality(80)
    ->thumb(200, 200)

Thumbnail is saved alongside the original with a thumb_ prefix:

  • Original: images/photo.webp
  • Thumbnail: images/thumb_photo.webp

Convert to WebP without resizing:

CompressedImage::make('Photo', 'photo')
    ->format('webp')
    ->quality(75)

Strict resize to exact dimensions:

CompressedImage::make('Photo', 'photo')
    ->width(1000)
    ->height(500)
    ->format('jpg')
    ->quality(90)

Compatibility

CompressedImage extends the standard MoonShine Image field, so all built-in File and Image methods are fully supported:

CompressedImage::make('Photo', 'photo')
    ->width(1000)
    ->format('webp')
    ->quality(80)
    ->disk('s3')               // custom filesystem disk
    ->dir('uploads/photos')    // storage subdirectory
    ->multiple()               // upload multiple images
    ->removable()              // allow deleting images
    ->keepOriginalFileName()   // preserve original filename

See the MoonShine docs for the full list of available File and Image methods.

License

MIT