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.
composer require scrapkit/file-processing-kitOptionally publish the config:
php artisan vendor:publish --tag="file-processing-kit-config"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.
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 pathSee 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
Ciphercontract lets a streaming driver be added later without changing calling code.
composer test
composer analyse
composer formatThe MIT License (MIT). See LICENSE.md.