Skip to content

Commit

Permalink
Dispatch job for default src when generating - #253
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed Oct 30, 2024
1 parent 232b2a8 commit 25c1361
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Commands/GenerateResponsiveVersionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Console\Command;
use Spatie\ResponsiveImages\Breakpoint;
use Spatie\ResponsiveImages\DimensionCalculator;
use Spatie\ResponsiveImages\Jobs\GenerateImageJob;
use Spatie\ResponsiveImages\Responsive;
use Spatie\ResponsiveImages\Source;
use Statamic\Console\RunsInPlease;
Expand Down Expand Up @@ -41,6 +43,23 @@ public function handle(AssetRepository $assets)
$assets->each(function (Asset $asset) {
$responsive = new Responsive($asset, new Parameters());

/**
* Dispatch job for default src
*/
$dimensions = app(DimensionCalculator::class)
->calculateForImgTag($responsive->defaultBreakpoint());

$width = $dimensions->getWidth();
$height = $dimensions->getHeight();

dispatch(app(GenerateImageJob::class, [
'asset' => $responsive->asset,
'params' => array_merge(['width' => $width, 'height' => $height]),
]));

/*
* Dispatch a job for each breakpoint
*/
$responsive->breakPoints()->each(function (Breakpoint $breakpoint) {
$breakpoint->sources()->each(function (Source $source) {
$source->dispatchImageJobs();
Expand Down

0 comments on commit 25c1361

Please sign in to comment.