diff --git a/app/Console/Commands/WebpMakeExecutables.php b/app/Console/Commands/WebpMakeExecutables.php new file mode 100644 index 00000000..14646a3b --- /dev/null +++ b/app/Console/Commands/WebpMakeExecutables.php @@ -0,0 +1,70 @@ + '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'); + } +} diff --git a/app/Services/MarhunPhotoService.php b/app/Services/MarhunPhotoService.php index 619a2f80..6464905c 100644 --- a/app/Services/MarhunPhotoService.php +++ b/app/Services/MarhunPhotoService.php @@ -50,9 +50,7 @@ class MarhunPhotoService Storage::disk('marhun')->putFileAs($directory, $request->gambarMarhun, "${marhunImageFileName}.${imageExtension}"); $stored_path = Storage::disk('marhun')->path("{$directory}{$marhunImageFileName}.${imageExtension}"); - $convertedFilePath = $this->optimizeImageToWebP($stored_path, $directory, $marhunImageFileName); - - $this->changeFileOwnerToServerUser($convertedFilePath); + $this->optimizeImageToWebP($stored_path, $directory, $marhunImageFileName); Storage::disk('marhun')->delete("{$directory}${marhunImageFileName}.${imageExtension}"); @@ -155,13 +153,5 @@ class MarhunPhotoService $webpCompiler = $this->getWebpCompilerByOS(); exec($webpCompiler . ' -preset photo ' . ' -resize 1280 720 ' . ' -mt ' .$originalFilePath . ' -o ' . $convertedFilePath); - - return $convertedFilePath; - } - - - private function changeFileOwnerToServerUser($filepath) - { - chown($filepath, get_current_user()); } }