PHPackages                             harorudo/media-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. [Image &amp; Media](/categories/media)
4. /
5. harorudo/media-compressor

ActiveLibrary[Image &amp; Media](/categories/media)

harorudo/media-compressor
=========================

A Laravel utility for compressing images, PDFs, and files - powered by Intervention Image and Ghostscript

v1.3.0(1mo ago)012MITPHPPHP ^8.2CI passing

Since Apr 9Pushed 1mo agoCompare

[ Source](https://github.com/eddyharold/media-compressor)[ Packagist](https://packagist.org/packages/harorudo/media-compressor)[ RSS](/packages/harorudo-media-compressor/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (3)Dependencies (7)Versions (6)Used By (0)

harorudo/media-compressor
=========================

[](#harorudomedia-compressor)

A Laravel utility for compressing images, PDFs, and files — powered by Intervention Image and Ghostscript.

---

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

[](#requirements)

- PHP ^8.2
- Laravel ^10.0 | ^11.0
- [Intervention Image](https://image.intervention.io) ^2.7
- [Ghostscript](https://www.ghostscript.com/releases/) (for PDF compression)

---

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

[](#installation)

```
composer require harorudo/media-compressor
```

Laravel auto-discovers the service provider. No manual registration needed.

### Verify your environment

[](#verify-your-environment)

Run the doctor command to confirm Ghostscript and the image backend are installed:

```
php artisan compression:doctor
```

### Install Ghostscript

[](#install-ghostscript)

**Ubuntu / Debian:**

```
sudo apt-get install ghostscript
```

**macOS:**

```
brew install ghostscript
```

**Windows:**Download from [ghostscript.com/releases](https://www.ghostscript.com/releases/) and ensure `gswin64c.exe` is in your PATH.

---

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

[](#configuration)

Publish the config file:

```
php artisan vendor:publish --tag=compression-config
```

`config/compression.php`:

```
return [
    'allowed_disks'  => ['public', 's3'],
    'max_file_size'  => 20 * 1024 * 1024, // 20 MB
];
```

---

Usage
-----

[](#usage)

Inject `CompressionUtil` directly or use the `Compression` facade.

### Images

[](#images)

```
use Harorudo\MediaCompressor\Facades\Compression;

// Compress an uploaded image
$result = Compression::compressImage(
    file: $request->file('photo'),
    quality: 75,
    maxWidth: 1280,
    format: 'webp'         // 'original' | 'webp' | 'jpeg' | 'png'
);

// Compress multiple images
$results = Compression::compressImages($request->file('photos'));

// Re-compress an already stored image
$result = Compression::recompressStoredImage('images/avatar.jpg', quality: 60);
```

### PDFs

[](#pdfs)

```
// Compress an uploaded PDF
$result = Compression::compressPdf(
    file: $request->file('document'),
    preset: 'ebook'        // 'screen' | 'ebook' | 'printer' | 'prepress'
);

// Re-compress a stored PDF
$result = Compression::recompressStoredPdf('pdfs/report.pdf', preset: 'ebook');

// Bulk re-compress stored PDFs
$results = Compression::recompressStoredPdfs(['pdfs/a.pdf', 'pdfs/b.pdf']);
```

#### PDF presets

[](#pdf-presets)

PresetImage DPIBest for`screen`72Email attachments, smallest size`ebook`150General use — recommended default`printer`300High-quality downloads`prepress`300 + colourPrint-ready, near-lossless### ZIP

[](#zip)

```
// Zip a single uploaded file
$result = Compression::zipUploadedFile($request->file('document'));

// Zip multiple stored files into one archive
$result = Compression::zipFiles(
    storagePaths: ['docs/report.pdf', 'docs/invoice.pdf'],
    archiveName: 'reports'
);
```

### Return value

[](#return-value)

Every method returns an array with savings stats:

```
[
    'path'            => 'pdfs/report.pdf',
    'original_size'   => 2048000,
    'compressed_size' => 819200,
    'saved_bytes'     => 1228800,
    'saved_percent'   => 60.0,
]
```

---

Security
--------

[](#security)

This package enforces the following guards on every operation:

- **MIME type validation** — server-side detection, client header is never trusted
- **File size limit** — configurable via `compression.max_file_size`
- **Storage disk allowlist** — configurable via `compression.allowed_disks`
- **Directory sanitization** — strips invalid characters to prevent path traversal
- **Safe filenames** — client filenames never touch the filesystem; hashed names are always used
- **Temp file cleanup** — guaranteed via `finally` blocks, even on failure

---

License
-------

[](#license)

MIT © [Eddy Harold](mailto:harorudo.dev@gmail.com)

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance91

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~12 days

Total

4

Last Release

43d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/36563793?v=4)[Eddy Harold](/maintainers/eddyharold)[@eddyharold](https://github.com/eddyharold)

---

Top Contributors

[![eddyharold](https://avatars.githubusercontent.com/u/36563793?v=4)](https://github.com/eddyharold "eddyharold (16 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/harorudo-media-compressor/health.svg)

```
[![Health](https://phpackages.com/badges/harorudo-media-compressor/health.svg)](https://phpackages.com/packages/harorudo-media-compressor)
```

###  Alternatives

[intervention/image-laravel

Laravel Integration of Intervention Image

1558.1M159](/packages/intervention-image-laravel)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

506511.0k27](/packages/bkwld-croppa)[hasinhayder/tyro-dashboard

Tyro Dashboard - Beautiful admin dashboard for managing Tyro roles, privileges, users, and settings

5452.7k](/packages/hasinhayder-tyro-dashboard)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1232.2k16](/packages/fleetbase-core-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
