#!/usr/bin/env php addArgument('sourceImagePath', InputArgument::REQUIRED, 'Absolute path to the input image') ->addArgument('imagePath', InputArgument::REQUIRED, 'Absolute path to the output image') ->addArgument('width', InputArgument::REQUIRED, 'Width for the crop') ->addArgument('height', InputArgument::REQUIRED, 'Height for the crop'); } protected function execute(InputInterface $input, OutputInterface $output): void { $imagePath = $input->getArgument('imagePath'); // Here we create the directory for the destination image, otherwise Imagick will crash $directory = \dirname($imagePath); if (!file_exists($directory)) { (new Filesystem())->mkdir($directory); /** @noinspection NotOptimalIfConditionsInspection */ if (!file_exists($directory)) { throw new \RuntimeException(sprintf('Could not create folder "%s" for Imagick.', $directory)); } } Image::fromFile($input->getArgument('sourceImagePath')) ->crop($input->getArgument('width'), $input->getArgument('height'), Image::CROP_BALANCED) ->save($imagePath); } }; $application = (new Application()) ->add($command) ->getApplication() ->setDefaultCommand($command->getName(), true) ->run();