Skip to content

Repository files navigation

File Processing Kit

Process files in a Laravel app through a single fluent pipeline — or with the underlying helpers on their own. The kit bundles:

  • Type detection — classify a file into a coarse FileCategory (image, document, spreadsheet, video, audio, archive, text, …) from its contents.
  • Image scaling — scale images down proportionally to fit within a bounding box (never enlarging), powered by intervention/image v3.
  • Compression — streaming gzip that keeps a constant memory footprint.
  • Encryption — symmetric encrypt/decrypt via Laravel's application key.
  • Storage — upload/download files on any Laravel filesystem disk.

When a file is an image, it is scaled proportionally automatically before it leaves the image domain (compression / encryption / storage), unless you scale it explicitly first.

Installation

composer require scrapkit/file-processing-kit

Optionally publish the config:

php artisan vendor:publish --tag="file-processing-kit-config"

Usage

Fluent pipeline

use Scrapkit\FileProcessingKit\Facades\FileProcessingKit;

// Store an upload — images are scaled down to the configured bounds first.
$path = FileProcessingKit::from($request->file('doc'))
    ->whenImage(fn ($file) => $file->scale(1920, 1080)) // optional override
    ->compress()
    ->encrypt()
    ->store('documents');            // second arg = disk (default when omitted)

// Reverse it.
$bytes = FileProcessingKit::fromDisk('documents', $path)
    ->decrypt()
    ->decompress()
    ->get();

from() accepts an UploadedFile, an SplFileInfo, or a local path. The source file is never mutated — every step works on a private temporary copy.

Standalone helpers

Each helper is a container singleton you can inject directly:

use Scrapkit\FileProcessingKit\Contracts\Compressor;
use Scrapkit\FileProcessingKit\Contracts\Cipher;
use Scrapkit\FileProcessingKit\Domain\Detection\TypeDetector;
use Scrapkit\FileProcessingKit\Domain\Image\ImageScaler;
use Scrapkit\FileProcessingKit\Domain\Storage\StorageHandler;

app(TypeDetector::class)->detect($path);          // FileCategory
app(ImageScaler::class)->scale($path, 1920, 1080); // → scaled temp path
app(Compressor::class)->compress($path);           // → gzip temp path
app(Cipher::class)->encrypt($path);                // → encrypted temp path
app(StorageHandler::class)->upload($path, 'dir');  // → stored path

Configuration

See config/file-processing-kit.php: default disk, image auto_scale / max_width / max_height / driver, gzip level, temp directory, and MIME overrides.

Note on encryption: files are encrypted in memory via Laravel's encrypter, which suits small to medium files. The Cipher contract lets a streaming driver be added later without changing calling code.

Testing

composer test
composer analyse
composer format

License

The MIT License (MIT). See LICENSE.md.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages