PHPackages                             walrussoup/laravel-shortpixel - 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. walrussoup/laravel-shortpixel

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

walrussoup/laravel-shortpixel
=============================

Shortpixel integration for laravel 9+

1.0.1(3y ago)02MITPHPPHP ^8.1

Since Jan 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/WalrusSoup/laravel-shortpixel)[ Packagist](https://packagist.org/packages/walrussoup/laravel-shortpixel)[ Docs](https://github.com/walrussoup/laravel-shortpixel)[ RSS](/packages/walrussoup-laravel-shortpixel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (14)Versions (3)Used By (0)

Shortpixel integration for laravel 9+
=====================================

[](#shortpixel-integration-for-laravel-9)

[![Latest Version on Packagist](https://camo.githubusercontent.com/27b42de3acae9308751612db909188f966befbb6e5c0c49f49cb6677f1b0df4c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77616c727573736f75702f6c61726176656c2d73686f7274706978656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/walrussoup/laravel-shortpixel)[![GitHub Tests Action Status](https://camo.githubusercontent.com/6c281eb2ae288575ba942d3a36ae152f4eaae181f89258ee0a20922dcc916e05/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f77616c727573736f75702f6c61726176656c2d73686f7274706978656c2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/walrussoup/laravel-shortpixel/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/94ba427043bd4ec26ec34e0dd9723d0395a64d2fe521790b281b43a130d41bbd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f77616c727573736f75702f6c61726176656c2d73686f7274706978656c2f466978253230504850253230636f64652532307374796c652532306973737565733f6c6162656c3d636f64652532307374796c65)](https://github.com/walrussoup/laravel-shortpixel/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/3150b19323e598d8d9568ec559dc62f6572cdae2ce7ee2a40bcff5816bcbdd7c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77616c727573736f75702f6c61726176656c2d73686f7274706978656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/walrussoup/laravel-shortpixel)

Makes using the shortpixel reducer api with laravel slightly less painful.

Archiving
---------

[](#archiving)

Archiving this to move to BunnyCDN. It's cheaper, and their API for using the on the fly image optimization is only $9.99 a month - literally cannot beat those prices.

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

[](#installation)

You can install the package via composer:

```
composer require walrussoup/laravel-shortpixel
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="laravel-shortpixel-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-shortpixel-config"
```

This is the contents of the published config file:

```
return [
    'api_key' => env('SHORTPIXEL_API_KEY'),
    'plugin_version' => env('SHORTPIXEL_PLUGIN_VERSION'),
    'log_channel' => env('SHORTPIXEL_LOG_CHANNEL', 'default')
];
```

Usage
-----

[](#usage)

I recommend setting a log channel specific to compression. I set this in logging &amp; simply set the output to another log file.

```
$laravelShortpixel = new WalrusSoup\LaravelShortpixel();
// set this up yourself or just let the container do it
$laravelShortpixel->setApiKey('your api key');
$laravelShortpixel->setPluginVersion('your plugin version');
$laravelShortpixel->setLogChannel('your log channel');

// Create an image configuration that compresses the original format and also outputs a webp format
$configuration = (new CompressionConfig())
        ->resizeToCover(500, 400)
        ->addImage('https://images.unsplash.com/photo-1611457194403-d3aca4cf9d11')
        // or, add multiple images using addImages()
        ->useLosslessCompression()
        ->convertToWebp()
        ->retainOriginalFormat();

/** @var ShortpixelCompressionResult $results */
$results = $laravelShortpixel->callShortpixelAndWait($configuration);

foreach($results as $result) {
    ray($result->getOriginalUrl(), $result->getCompressedUrl());
}
```

### Understanding The API... kinda

[](#understanding-the-api-kinda)

The Shortpixel API accepts the original configuration in it's entirety to keep track of compression results. If you are not using a long-running job with `callShortpixelAndWait()` you will need to store the full configuration somewhere. I recommend letting a job handle this via its serialization.

The other thing is keeping track of the original names. For the sake of keeping things consistent, I made some methods for these.

```
// If you requested a conversion to another format, this will help you get the original name
$originalName = $result->getOriginalFilenameWithNewExtension();
// WEBP and AVIF are split off into a separate key, so you can use this to get it I suppose
$originalNameWebp = $result->getOriginalFilenameWebpLossy();
// Again, these are names only. You will need to still download the URL from the other key, for instance:
file_get_contents($result->getWebpLosslessURL());
```

### Job Example

[](#job-example)

This is how I use it. It could probably be better, but it works for my case since jobs can be retried later.

```
namespace App\Jobs;

use WalrusSoup\LaravelShortpixel\CompressionConfig;
use WalrusSoup\LaravelShortpixel\LaravelShortpixel;

class CompressImage implements ShouldQueue
{
    public function __construct(public CompressionConfig $config) {}

    public function handle(LaravelShortpixel $laravelShortpixel)
    {
        // Queue the job and forget about it for 5 minutes
        $laravelShortpixel->callShortPixel($this->config);
        // Fetch the result later
        CheckCompressionResults::dispatch($this->config)->delay(now()->addMinutes(5));
    }
}

// another job
class CheckCompressionResults implement ShouldQueue
{
    public $tries = 1;

    public function __construct(public CompressionConfig $config) {}

    public function handle(LaravelShortpixel $laravelShortpixel)
    {
        // Again, we have to give them the original config. It won't compress again, it will just return the results
        $results = $laravelShortpixel->callShortPixelAndWait($this->config);

        foreach($results as $result) {
            // do something with the result
        }
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [JL](https://github.com/WalrusSoup)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 63.6% 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 ~1 days

Total

2

Last Release

1211d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bc3e4304e117f1a73791b42d80edb079b90724d7a3078850041874124be1d54d?d=identicon)[WalrusSoup](/maintainers/WalrusSoup)

---

Top Contributors

[![WalrusSoup](https://avatars.githubusercontent.com/u/5719851?v=4)](https://github.com/WalrusSoup "WalrusSoup (14 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

laravelWalrusSouplaravel-shortpixel

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/walrussoup-laravel-shortpixel/health.svg)

```
[![Health](https://phpackages.com/badges/walrussoup-laravel-shortpixel/health.svg)](https://phpackages.com/packages/walrussoup-laravel-shortpixel)
```

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[saasykit/laravel-open-graphy

An awesome open graph image (social cards) generator package for Laravel.

13057.0k](/packages/saasykit-laravel-open-graphy)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[muhammadhuzaifa/telescope-guzzle-watcher

Telescope Guzzle Watcher provide a custom watcher for intercepting http requests made via guzzlehttp/guzzle php library. The package uses the on\_stats request option for extracting the request/response data. The watcher intercept and log the request into the Laravel Telescope HTTP Client Watcher.

98239.8k1](/packages/muhammadhuzaifa-telescope-guzzle-watcher)[ace-of-aces/laravel-image-transform-url

Easy, URL-based image transformations inspired by Cloudflare Images.

1756.4k](/packages/ace-of-aces-laravel-image-transform-url)[spatie/laravel-mailcoach-sdk

An SDK to easily work with the Mailcoach API in Laravel apps

41290.2k1](/packages/spatie-laravel-mailcoach-sdk)

PHPackages © 2026

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