Skip to content

Commit

Permalink
Generate preview specifications once
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
st3iny committed Nov 8, 2022
1 parent 002dd7f commit c422698
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/Command/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class Generate extends Command {
/** @var ?GlobalStoragesService */
protected $globalService;

/** @var int[][] */
protected array $sizes;
protected array $specifications;

protected IUserManager $userManager;
protected IRootFolder $rootFolder;
Expand Down Expand Up @@ -110,7 +109,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->setFormatter($formatter);
$this->output = $output;

$this->sizes = SizeHelper::calculateSizes($this->config);
// Generate preview specifications once
$sizes = SizeHelper::calculateSizes($this->config);
$this->specifications = array_merge(
array_map(static function ($squareSize) {
return ['width' => $squareSize, 'height' => $squareSize, 'crop' => true];
}, $sizes['square']),
array_map(static function ($heightSize) {
return ['width' => -1, 'height' => $heightSize, 'crop' => false];
}, $sizes['height']),
array_map(static function ($widthSize) {
return ['width' => $widthSize, 'height' => -1, 'crop' => false];
}, $sizes['width'])
);

$inputPaths = $input->getOption('path');
if ($inputPaths) {
Expand Down Expand Up @@ -220,18 +231,7 @@ private function parseFile(File $file): void {
}

try {
$specifications = array_merge(
array_map(function ($squareSize) {
return ['width' => $squareSize, 'height' => $squareSize, 'crop' => true];
}, $this->sizes['square']),
array_map(function ($heightSize) {
return ['width' => -1, 'height' => $heightSize, 'crop' => false];
}, $this->sizes['height']),
array_map(function ($widthSize) {
return ['width' => $widthSize, 'height' => -1, 'crop' => false];
}, $this->sizes['width'])
);
$this->previewGenerator->generatePreviews($file, $specifications);
$this->previewGenerator->generatePreviews($file, $this->specifications);
} catch (NotFoundException $e) {
// Maybe log that previews could not be generated?
} catch (\InvalidArgumentException $e) {
Expand Down

0 comments on commit c422698

Please sign in to comment.