Download the PHP package justsmiletoo/laravel-file-compressor without Composer
On this page you can find all versions of the php package justsmiletoo/laravel-file-compressor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download justsmiletoo/laravel-file-compressor
More information about justsmiletoo/laravel-file-compressor
Files in justsmiletoo/laravel-file-compressor
Package laravel-file-compressor
Short Description Automatically compress images, PDFs and videos on upload in Laravel. Auto-detects MIME type and applies the right compressor with zero configuration.
License MIT
Informations about the package laravel-file-compressor
Laravel File Compressor
Automatically compress images, PDFs and videos on upload in Laravel. Auto-detects the MIME type and applies the right compressor — zero config needed.
Requirements
- PHP 8.2+
- Laravel 11 or 12
- GD extension (default) or Imagick
- Optional: Ghostscript (
gs) for PDF compression - Optional: FFmpeg (
ffmpeg) for video compression
Installation
The service provider is auto-discovered. To publish the config file:
System binaries (optional)
For PDF compression, install Ghostscript:
For video compression, install FFmpeg:
Usage
Auto-detect and compress
The compress() method detects the file type and delegates to the right compressor:
Type-specific methods
Skip MIME detection and call a compressor directly:
Presets
Use named presets for common image use cases:
Define your own presets in the config:
Resize modes
scale(default) — Proportionally scale down. Never upscales. Aspect ratio preserved.cover— Crop and resize to fill exact dimensions (like CSSobject-fit: cover).
Per-call options
Override config values for a single call:
CompressionResult
Every compression call returns a CompressionResult DTO:
Integration example
Typical usage in a file upload service:
Check support
Configuration
| Key | Default | Description |
|---|---|---|
enabled |
true |
Global toggle. Set to false to skip all compression. |
temp_dir |
sys_get_temp_dir() |
Temporary directory for processing. |
| Image | ||
image.driver |
gd |
Image driver: gd or imagick. |
image.quality |
80 |
JPEG/WebP quality (1-100). |
image.max_width |
1920 |
Max width in pixels. Aspect ratio preserved. |
image.max_height |
1080 |
Max height in pixels. Aspect ratio preserved. |
image.mode |
scale |
Resize mode: scale (proportional) or cover (crop to fill). |
image.convert_to |
null |
Convert format: null (keep original), webp, jpg, png. |
image.presets |
[...] |
Named presets with per-preset options. See Presets. |
pdf.binary |
gs |
Path to the Ghostscript binary. |
pdf.quality |
ebook |
Preset: screen (72dpi), ebook (150dpi), printer (300dpi), prepress. |
pdf.timeout |
60 |
Process timeout in seconds. |
| Video | ||
video.binary |
ffmpeg |
Path to the FFmpeg binary. |
video.codec |
libx264 |
Video codec. |
video.crf |
28 |
Constant Rate Factor (0-51). Lower = better quality, larger file. |
video.preset |
medium |
Encoding speed preset. Slower = better compression. |
video.max_width |
1280 |
Max width in pixels (never upscales). |
video.audio_bitrate |
128k |
Audio bitrate. |
video.timeout |
300 |
Process timeout in seconds. |
All values can be overridden via environment variables. See config/file-compressor.php for the full list.
Handling unsupported files
If a file type is not supported, compress() throws UnsupportedFileTypeException. You can check support beforehand:
Or catch the exception:
Temp file cleanup
Compressed files are written to the configured temp_dir. After storing the compressed file to your disk, the temp file can be safely deleted. The OS will also clean up temp files periodically.
Testing
Place test fixtures (sample.jpg, sample.pdf, sample.mp4) in tests/Fixtures/ to enable all tests.
License
MIT. See LICENSE.
All versions of laravel-file-compressor with dependencies
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/contracts Version ^11.0|^12.0|^13.0
intervention/image Version ^3.0