/** * {@inheritdoc} */ public function execute(CommandParams $params, CommandExecutionContext $executionContext) { $fileName = $params->getFirstArgument(); if (!$executionContext->hasFileInWorkingDirectory($fileName)) { throw new ExecutionFailedException("File '{$fileName}' does not exist."); } $img = $this->imageManager->make($executionContext->getPathOfFileInWorkingDirectory($fileName)); if (!$params->hasSecondArgument()) { return $this->returnImage($img, $params); } list($width, $height) = $this->parseDimension($params->getSecondArgument()); switch ($params->getThirdArgument()) { case 'stretch': $img->resize($width, $height); break; case 'fit': $img->fit($width, $height); break; case 'crop': $x = $this->filterIntOrNullArgument($params->getArgument(3)); $y = $this->filterIntOrNullArgument($params->getArgument(4)); $img->crop($width, $height, $x, $y); break; default: $img->resize($width, $height, function (Constraint $constraint) { $constraint->aspectRatio(); }); break; } return $this->returnImage($img, $params); }