73 lines
1.9 KiB
PHP
73 lines
1.9 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()
|
|
{
|
|
$DS = DIRECTORY_SEPARATOR;
|
|
|
|
$cwebp_compilers = [
|
|
'Windows' => 'binaries' . $DS . 'libwebp-1.2.4-windows-x64' . $DS . 'bin' . $DS . 'cwebp',
|
|
'Linux' => 'binaries' . $DS . 'libwebp-1.2.4-linux-x86-64' . $DS . 'bin' . $DS .'cwebp',
|
|
'Darwin' => [
|
|
'X86-64' => 'binaries' . $DS . 'libwebp-1.2.4-mac-X86-64' . $DS . 'bin' . $DS . 'cwebp',
|
|
'arm64' => 'binaries' . $DS . 'libwebp-1.2.4-mac-arm64' . $DS . 'bin' . $DS .'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 ($server_operating_system === 'Linux') {
|
|
$webp_binary_path = resource_path($cwebp_compilers[$server_operating_system]);
|
|
}
|
|
|
|
exec('chmod +x ' . $webp_binary_path, $output, $result);
|
|
|
|
$this->info('Webp binaries are now executables');
|
|
}
|
|
}
|