Skip to content

Commit

Permalink
optimize images
Browse files Browse the repository at this point in the history
  • Loading branch information
fiste788 committed Nov 27, 2024
1 parent 3bfda40 commit af57239
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Command/ConvertTeamImageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
$newFile = new SplFileInfo($tmpFile->getPath() . DS . $tmpFile->getBasename($tmpFile->getExtension()) . "webp");
if ($tmpFile->isFile()) {
$io->info($newFile->__toString());
Image::useImageDriver(ImageDriver::Gd)->load($tmpFile->getPathname())->quality(80)->save($newFile->getPathname());
Image::useImageDriver(ImageDriver::Gd)->load($tmpFile->getPathname())->optimize()->quality(80)->save($newFile->getPathname());
$team->photo = $newFile->getFilename();
$team->photo_size = $newFile->getSize();
$team->photo_type = $newFile->getType();
Expand All @@ -75,7 +75,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
foreach ($finder->getIterator() as $file) {
$io->info($file->__toString());
$newFile = new SplFileInfo($file->getPath() . DS . $file->getBasename($file->getExtension()) . "webp");
Image::useImageDriver(ImageDriver::Gd)->load($file->getPathname())->quality(80)->save($newFile->getPathname());
Image::useImageDriver(ImageDriver::Gd)->load($file->getPathname())->optimize()->quality(80)->save($newFile->getPathname());
}
$teamsTable->save($team);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Model/Table/TeamsTable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace App\Model\Table;
Expand Down Expand Up @@ -144,8 +145,8 @@ function (
$array = [$tmpFile => $tmpFileName->getFilename()];
foreach (Team::$size as $value) {
if ($value < $image->getWidth()) {
$tmp = tempnam(TMP, (string)$value) . '.' . $tmpFileName->getExtension();
$image->width($value)->optimize()->save($tmp);
$tmp = tempnam(TMP, (string)$value) . '.webp';
$image->width($value)->quality(80)->optimize()->save($tmp);
$array[$tmp] = $value . 'w' . DS . strtolower($tmpFileName->getFilename());
}
}
Expand Down

0 comments on commit af57239

Please sign in to comment.