PHPackages                             andhalebabalu/laravel-file-compressor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. andhalebabalu/laravel-file-compressor

ActiveLibrary

andhalebabalu/laravel-file-compressor
=====================================

Laravel package for automatic image compression and storage during file uploads.

01↓100%PHP

Since Mar 15Pushed 1w agoCompare

[ Source](https://github.com/andhalebabalu/laravel-file-compressor)[ Packagist](https://packagist.org/packages/andhalebabalu/laravel-file-compressor)[ RSS](/packages/andhalebabalu-laravel-file-compressor/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel File Compressor
=======================

[](#laravel-file-compressor)

`laravel-file-compressor` is a Laravel package that compresses uploaded images before saving them to Laravel storage. It supports JPEG, PNG, and WebP uploads and returns the stored path after compression.

Features
--------

[](#features)

- Compress uploaded images before storing them
- Support for JPEG, PNG, and WebP
- Configurable compression quality
- Configurable storage disk
- Publishable configuration
- Laravel package discovery for provider and facade

Requirements
------------

[](#requirements)

- PHP 8.0+
- Laravel 9, 10, 11, or 12
- [Intervention Image](https://image.intervention.io/)

Installation
------------

[](#installation)

Install the package with Composer:

```
composer require vendor/laravel-file-compressor
```

If you publish this package under your own Composer vendor, replace `vendor` with your actual vendor name.

Package Structure
-----------------

[](#package-structure)

```
laravel-file-compressor/
|-- composer.json
|-- README.md
|-- config/
|   `-- file-compressor.php
`-- src/
    |-- Exceptions/
    |   |-- FileStorageException.php
    |   `-- UnsupportedFileTypeException.php
    |-- Facades/
    |   `-- FileCompressor.php
    |-- Support/
    |   `-- FileHelper.php
    |-- FileCompressorManager.php
    `-- FileCompressorServiceProvider.php

```

Configuration
-------------

[](#configuration)

Publish the package configuration:

```
php artisan vendor:publish --tag=file-compressor-config
```

The generated config file contains:

```
return [
    'compression_quality' => 75,
    'allowed_file_types' => ['jpg', 'jpeg', 'png', 'webp'],
    'storage_disk' => 'public',
];
```

Usage
-----

[](#usage)

### Facade Example

[](#facade-example)

```
use FileCompressor;

$path = FileCompressor::compressAndStore($request->file('image'), 'uploads');
```

The method will:

1. Validate the uploaded file type against the configured allow list.
2. Compress the image using the configured quality.
3. Store the compressed image on the configured Laravel disk.
4. Return the stored file path, for example `uploads/abc123-file.jpg`.

### Custom Disk or Quality

[](#custom-disk-or-quality)

```
$path = FileCompressor::compressAndStore(
    $request->file('image'),
    'uploads',
    's3',
    ['quality' => 65]
);
```

Example Controller
------------------

[](#example-controller)

```
