All Projects → czim → file-handling

czim / file-handling

Licence: MIT license
File Handling Helper

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to file-handling

Nodestream
Storage-agnostic streaming library for binary data transfers
Stars: ✭ 70 (+400%)
Mutual labels:  storage, upload
kipp
A flexible file storage server
Stars: ✭ 33 (+135.71%)
Mutual labels:  storage, upload
S3 Uploader
🍎 macOS Electron+React App for uploading files to S3 directly from Status Bar
Stars: ✭ 119 (+750%)
Mutual labels:  storage, upload
Miniflix
Miniflix - A smaller version of Netflix powered by Cloudinary
Stars: ✭ 58 (+314.29%)
Mutual labels:  storage, upload
Cakephp File Storage
Abstract file storage and upload plugin for CakePHP. Write to local disk, FTP, S3, Dropbox and more through a single interface. It's not just yet another uploader but a complete storage solution.
Stars: ✭ 202 (+1342.86%)
Mutual labels:  storage, upload
react-native-modest-cache
💾 Simple cache for AsyncStorage
Stars: ✭ 23 (+64.29%)
Mutual labels:  storage
speed-cloudflare-cli
📈 Measure the speed and consistency of your internet connection using speed.cloudflare.com
Stars: ✭ 99 (+607.14%)
Mutual labels:  upload
gcsfs
Google Cloud Storage filesystem for PyFilesystem2
Stars: ✭ 36 (+157.14%)
Mutual labels:  storage
MeowDB.js
Database in JSON (Node.JS Library)
Stars: ✭ 12 (-14.29%)
Mutual labels:  storage
shoebox
ShoeBox is a Kotlin library for persistent data storage that supports views and the observer pattern. While often used with Kweb, it doesn't need to be.
Stars: ✭ 48 (+242.86%)
Mutual labels:  storage
file-upload-with-preview
🖼 Simple file-upload utility that shows a preview of the uploaded image. Written in TypeScript. No dependencies. Works well with or without a framework.
Stars: ✭ 406 (+2800%)
Mutual labels:  upload
ansible-unity
Ansible Modules for Dell EMC Unity
Stars: ✭ 19 (+35.71%)
Mutual labels:  storage
Cherry-Node
Cherry Network's node implemented in Rust
Stars: ✭ 72 (+414.29%)
Mutual labels:  storage
ic-firebase-uploader
This component is a multi-file uploader for firebase
Stars: ✭ 21 (+50%)
Mutual labels:  upload
react-native-s3
React Native app to upload and display images from Amazon S3 using AWS Amplify as the back end service.
Stars: ✭ 41 (+192.86%)
Mutual labels:  storage
ECS-CommunityEdition
ECS Community Edition "Free & Frictionless"
Stars: ✭ 125 (+792.86%)
Mutual labels:  storage
angular-progress-http
[DEPRECATED] Use @angular/common/http instead
Stars: ✭ 43 (+207.14%)
Mutual labels:  upload
MIT6.824-2021
4 labs + 2 challenges + 4 docs
Stars: ✭ 594 (+4142.86%)
Mutual labels:  storage
simple http server
simple http server for upload and download
Stars: ✭ 101 (+621.43%)
Mutual labels:  upload
pepic
Image and video proxy for my pet-projects
Stars: ✭ 35 (+150%)
Mutual labels:  upload

Latest Version on Packagist Software License Build Status Coverage Status

File Handling and Storage Helper

Handles uploads, manipulations and (external) storage

Changelog

View the changelog.

Usage

This package is framework-independent.

Here's an example of how to set up variant processing in general:

<?php
    // Set up a storage implementation (for your framework of choice), and a PSR-11 container implementation.
    /** @var \Czim\FileHandling\Contracts\Storage\StorageInterface $storage */
    /** @var \Psr\Container\ContainerInterface $container */
    
    $sourcePath = 'storage/input-file-name.jpg';
    

    // Source File
    $helper      = new \Czim\FileHandling\Support\Content\MimeTypeHelper;
    $interpreter = new \Czim\FileHandling\Support\Content\UploadedContentInterpreter;
    $downloader  = new \Czim\FileHandling\Support\Download\UrlDownloader($helper);
    $factory     = new \Czim\FileHandling\Storage\File\StorableFileFactory($helper, $interpreter, $downloader);

    $file = $factory->makeFromLocalPath($sourcePath);

    // Handler
    $strategyFactory = new \Czim\FileHandling\Variant\VariantStrategyFactory($container);
    $strategyFactory->setConfig([
        'aliases' => [
            'resize'     => \Czim\FileHandling\Variant\Strategies\ImageResizeStrategy::class,
            'autoOrient' => \Czim\FileHandling\Variant\Strategies\ImageAutoOrientStrategy::class,
        ],
    ]);

    $processor = new \Czim\FileHandling\Variant\VariantProcessor($factory, $strategyFactory);

    $handler = new \Czim\FileHandling\Handler\FileHandler($storage, $processor);
    
    $handler->process($file, new Target($file->path()), [
        'variants' => [
            'tiny' => [
                'autoOrient' => [],
                'resize' => [
                    'dimensions' => '30x30',
                ],
            ],
            'orient' => [
                'autoOrient' => [
                    'quiet' => false,
                ],
            ],
        ],
    ]);

For Laravel, you could use the following framework specific storage implementation:

<?php
    // Storage
    $storage = new \Czim\FileHandling\Storage\Laravel\LaravelStorage(
        \Storage::disk('testing'),
        true,
        url('testing')
    );
   
    // If you're using a Laravel version that does not have a PSR-11 compliant container yet:
    $container = new \Czim\FileHandling\Support\Container\LaravelContainerDecorator(app());
    
    app()->bind(\Imagine\Image\ImagineInterface::class, \Imagine\Gd\Imagine::class);

It is recommended of course to use the dependency container / IoC solution of your framework to simplify the above approach.

Custom Container

If you don't have a feasible PSR-11 container available, you can use a very simple implementation provided with this package.

<?php
    $container = new \Czim\FileHandling\Support\Container\SimpleContainer;
    
    $container->registerInstance(
        \Czim\FileHandling\Variant\Strategies\ImageResizeStrategy::class,
        new \Czim\FileHandling\Variant\Strategies\ImageResizeStrategy(
            new \Czim\FileHandling\Support\Image\Resizer(
                new \Imagine\Gd\Imagine
            )
        )
    );
    $container->registerInstance(
        \Czim\FileHandling\Variant\Strategies\ImageAutoOrientStrategy::class,
        new \Czim\FileHandling\Variant\Strategies\ImageAutoOrientStrategy(
                new \Czim\FileHandling\Support\Image\OrientationFixer(new \Imagine\Gd\Imagine)
            )
    );

Storage

Files can be stored using customizable storage implementations.

A very simple adapter/decorator for the Laravel storage is provided. For any other framework/setup you will (for now) have to write your own implementation of the \Czim\FileHandling\Contracts\Storage\StorageInterface.

Variants

When a file is processed, variants can be created automatically and stored along with the original.

These can be resizes, crops or recolors of the original image. This package is set up to allow you to easily create your own strategies for making variants.

A single variant is defined by one or more strategy steps, making it possible to combine effects and re-use strategies.

Variants can be re-created from the original.

Note that it this package is designed to easily create and add in custom variant strategies. Consider the source code for the strategies listed below examples to get you started.

Image Strategies

Included strategies for image manipulation:

  • ImageAutoOrientStrategy: Re-orients rotated or flipped images.

  • ImageResizeStrategy: Resizes (and crops) images.
    (Uses Stapler's options & approach to resizes.)

  • ImageWatermarkStrategy: Pastes a watermark onto an image.
    In any corner or the center.
    Options:
    position (string): top-left, top-right, center, bottom-left, bottom-right.
    watermark (string): full path to the watermark image.
    The watermark should be a PNG (transparent) image for best results.

  • ImageOptimizationStrategy Optimizes images to decreate their file size.

    This strategy requires installation of spatie/image-optimizer.

    In order for it to work, you'll need to install a few image optimizers as well:

    • jpegoptim
    • optipng
    • pngquant
    • svgo
    • gifsicle

    Installation example for Ubuntu:

    sudo apt-get install jpegoptim optipng pngquant gifsicle
    sudo npm install -g svgo

    Installation example for MacOS, using Homebrew:

    brew install jpegoptim optipng pngquant svgo gifsicle

Video Strategies

Included strategies for video manipulation:

  • VideoScreenshotStrategy: Extracts a video frame for a preview.
    (Requires ffmpeg/ffprobe).
    Options:
    seconds (int): the second of video runtime to take the shot at.
    percentage (int): the percentage of video runtime to take the shot at (overruled by seconds). ffmpeg (string): path to ffmpeg binary (if not /usr/bin/ffmpeg). ffprobe (string): path to ffprobe binary (if not /usr/bin/ffprobe).

Variant Gotcha

When using the resize strategy while working with potentially EXIF-rotated images, keep in mind that portrait/landscape width/height only resizes may run into trouble unless they are auto-oriented first.

For this reason, it is recommended to precede the ImageResizeStrategy by the ImageAutoOrientStrategy.

In general, it is always a good idea to consider the order in which strategies are applied.

You may also opt to combine multiple strategies into one strategy class, if efficiency is important. You may use this approach to prevent opening/saving the same file more than once.

Configuration

Configuration of file handling is set by injecting an associative array with a tree structure into the FileHandler.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].