71 lines
1.8 KiB
PHP
71 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
class WebpMakeExecutables extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'webp:make_exec';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Make webp binaries executable';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$cwebp_compilers = [
|
|
'Windows' => 'binaries\libwebp-1.2.4-windows-x64\bin\cwebp',
|
|
'Linux' => 'binaries\libwebp-1.2.4-linux-x86-64\bin\cwebp',
|
|
'Darwin' => [
|
|
'X86-64' => 'binaries\libwebp-1.2.4-mac-X86-64\bin\cwebp',
|
|
'arm64' => 'binaries\libwebp-1.2.4-mac-arm64\bin\cwebp',
|
|
],
|
|
];
|
|
|
|
$server_operating_system = explode(' ', trim(php_uname()))[0];
|
|
$server_processor_architecture = trim(php_uname('m'));
|
|
|
|
|
|
if($server_operating_system === 'Windows'){
|
|
$this->error('Windows OS are not permitted');
|
|
return;
|
|
}
|
|
|
|
if ($server_operating_system === 'Darwin') {
|
|
$webp_binary_path = resource_path($cwebp_compilers['Darwin'][$server_processor_architecture]);
|
|
}
|
|
|
|
if (in_array($server_operating_system, array_keys($cwebp_compilers))) {
|
|
$webp_binary_path = resource_path($cwebp_compilers[$server_operating_system]);
|
|
}
|
|
|
|
$result = exec('chmod +x ' . $webp_binary_path, $output, $result);
|
|
|
|
$this->info('Webp binaries are now executables');
|
|
}
|
|
}
|