-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: implement image compressor commands
- Loading branch information
1 parent
ba3c1de
commit a32a92b
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Intervention\Image\ImageManager; | ||
use Intervention\Image\Drivers\Imagick\Driver; | ||
|
||
class ConvertImagesToWebp extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:images-to-webp'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$basePath = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public'; | ||
|
||
$files = \File::files($basePath); | ||
foreach ($files as $file) { | ||
$imageType = exif_imagetype($file->getPathname()); | ||
if ($imageType === false) { | ||
continue; | ||
} | ||
if ($imageType === IMAGETYPE_WEBP) { | ||
dump($file->getPathname()); | ||
continue; | ||
} | ||
$manager = new ImageManager(new Driver()); | ||
$image = $manager->read($file->getPathname()); | ||
$image->toWebp()->save($basePath . '\\' . $file->getBasename()); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Intervention\Image\Drivers\Imagick\Driver; | ||
use Intervention\Image\ImageManager; | ||
|
||
class ReduceImagesSizes extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:reduce-images-sizes'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$basePath = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public'; | ||
|
||
$files = \File::files($basePath); | ||
foreach ($files as $file) { | ||
|
||
if (exif_imagetype($file->getPathname()) === false) { | ||
continue; | ||
} | ||
|
||
$manager = new ImageManager(new Driver()); | ||
$image = $manager->read($file->getPathname()); | ||
$image->scaleDown(900); | ||
$image | ||
->save($basePath . DIRECTORY_SEPARATOR . $file->getBasename()); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters