Medialibrary can be installed via composer:
$ composer require spatie/laravel-medialibrary:^6.0.0
The package will automatically register a service provider.
You need to publish and run the migration:
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="migrations"
php artisan migrate
Publishing the config file is optional:
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="config"
This is the default content of the config file:
return [
'default_filesystem' => 'public',
'max_file_size' => 1024 * 1024 * 10,
'queue_name' => '',
'media_model' => Spatie\MediaLibrary\Media::class,
'image_driver' => 'gd',
'custom_url_generator_class' => null,
'custom_path_generator_class' => null,
's3' => [
'domain' => 'https://xxxxxxx.s3.amazonaws.com',
],
'remote' => [
'extra_headers' => [
'CacheControl' => 'max-age=604800',
],
],
'image_generators' => [
Spatie\MediaLibrary\ImageGenerators\FileTypes\Image::class,
Spatie\MediaLibrary\ImageGenerators\FileTypes\Pdf::class,
Spatie\MediaLibrary\ImageGenerators\FileTypes\Svg::class,
Spatie\MediaLibrary\ImageGenerators\FileTypes\Video::class,
],
'image_optimizers' => [
Spatie\ImageOptimizer\Optimizers\Jpegoptim::class => [
'--strip-all',
'--all-progressive',
],
Spatie\ImageOptimizer\Optimizers\Pngquant::class => [
'--force',
],
Spatie\ImageOptimizer\Optimizers\Optipng::class => [
'-i0',
'-o2',
'-quiet',
],
Spatie\ImageOptimizer\Optimizers\Svgo::class => [
'--disable=cleanupIDs',
],
Spatie\ImageOptimizer\Optimizers\Gifsicle::class => [
'-b',
'-O3',
],
],
'temporary_directory_path' => null,
'ffmpeg_binaries' => '/usr/bin/ffmpeg',
'ffprobe_binaries' => '/usr/bin/ffprobe',
];
By default medialibrary will store it's files on Laravel's public
disk. If you want a dedicated disk you should add a disk to app/config/filesystems.php
. This would be a typical configuration:
...
'disks' => [
...
'media' => [
'driver' => 'local',
'root' => public_path('media'),
],
...
Don't forget to ignore the directory of your configured disk so the files won't end up in your git repo.
If you are planning on working with image manipulations it's recommended to configure a queue on your server and specify it in the config file.
Want to use S3? Then follow Laravel's instructions on how to add the S3 Flysystem driver.
##Optimization tools
Medialibrary will use these tools to optimize converted images if they are present on your system:
Here's how to install all the optimizers on Ubuntu:
sudo apt-get install jpegoptim
sudo apt-get install optipng
sudo apt-get install pngquant
sudo npm install -g svgo
sudo apt-get install gifsicle
And here's how to install the binaries on MacOS (using Homebrew):
brew install jpegoptim
brew install optipng
brew install pngquant
brew install svgo
brew install gifsicle