e200/mediavel

Laravel media library package

dev-master 2019-12-04 08:30 UTC

README

Latest Version on Packagist Total Downloads Build Status StyleCI

A media library handler for Laravel.

Right now, it only supports upload images and generate thumbnails from them.

Installation

Via Composer

$ composer require e200/mediavel

Usage

namespace App\Http\Controllers;

use Illuminate\Routing\Controller;
use e200\Mediavel\Facades\MediaLibrary;

class ImageController extends Controller
{
    public function upload(Request $request)
    {
        $uploadedImage = $request->image;

        $media = $mediaLibrary
          ->add($uploadedImage)           // Store the image
          ->preserveOriginal()            // Do not touch the original file
          ->resize('small', [75, 75])     // Creates a thumbnail (75x75) derived from the original image
          ->resize('medium', [150, 150])  // Creates a thumbnail (150x150)
          ->resize('large', [1024, 300]); // Creates a thumbnail (1024x300);

        $media->id;            // 1
        $media->relative_path; // /images/2018/12/sl290s8xq0is9wqjk.jpg
        $media->url;           // http://localhost:8000/images/2019/06/5cf6976f20dfb.jpg

        $thumbs = $media->thumbs();

        $thumbs['small']->path;  // /images/2018/12/5cf6976f20dfb-75x75.jpg
        $thumbs['medium']->path; // /images/2018/12/5cf6976f20dfb-150x150.jpg
        $thumbs['large']->path;  // /images/2018/12/5cf6976f20dfb-1024x300.jpg
    }
}

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email eleandro@inbox.ru instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.