Devise\Media\Images\Manager::cropAndSaveFile PHP Method

cropAndSaveFile() public method

Crop and save an image
public cropAndSaveFile ( $input ) : string
$input
return string
    public function cropAndSaveFile($input)
    {
        $imagePath = array_get($input, 'image', null);
        if (is_null($imagePath)) {
            return false;
        }
        // lots of variables to make this code easier to read
        $width = $input['cropper']['width'];
        $height = $input['cropper']['height'];
        $cropWidth = $input['cropper']['w'];
        $cropHeight = $input['cropper']['h'];
        $cropX = $input['cropper']['x'];
        $cropY = $input['cropper']['y'];
        // find the paths
        $croppedName = $this->getNewCroppedName($imagePath, $width, $height);
        $localPath = isset($input['category']) ? $this->CategoryPaths->fromDot($input['category']) : '';
        $serverPath = $this->CategoryPaths->serverPath($localPath);
        $imagePath = $serverPath . $input['image'];
        // resize and crop image and save it to media directory
        $image = $this->Images->cropAndResizeImage($imagePath, $width, $height, $cropWidth, $cropHeight, $cropX, $cropY);
        $this->Images->saveImage($image, $serverPath . $croppedName);
        return $croppedName;
    }