Skip to content

Instantly share code, notes, and snippets.

@acodeninja
Created August 13, 2018 10:22
Show Gist options
  • Save acodeninja/86eb5447862f3c883b73b36ed75ac675 to your computer and use it in GitHub Desktop.
Save acodeninja/86eb5447862f3c883b73b36ed75ac675 to your computer and use it in GitHub Desktop.
Generate responsive images for medialibrary post upgrade
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class GenerateResponsiveImages extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'medialibrary:generate-responsive';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate responsive images for every image already uploaded.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$media = app(config('medialibrary.media_model'))::all();
$generator = app('Spatie\MediaLibrary\ResponsiveImages\ResponsiveImageGenerator');
foreach ($media as $medium) {
$this->output->writeln('<info>Processing media#'.$medium->id.': '.$medium->getPath().'</info>');
$generator->generateResponsiveImages($medium);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment