protected function croppedImagePath($field, $type = 'image')
{
// gather info about this file and where it should be versioned
$info = $this->MediaPaths->fileVersionInfo($field->values->image);
// setting variables so we can easily access them later
$width = $field->values->{$type . '_width'};
$height = $field->values->{$type . '_height'};
$cropWidth = $field->values->{$type . '_crop_w'};
$cropHeight = $field->values->{$type . '_crop_h'};
$cropX = $field->values->{$type . '_crop_x'};
$cropY = $field->values->{$type . '_crop_y'};
// this is the croppedImagePath
$croppedImagePath = "{$info->versiondir}/{$info->filename}_{$width}_{$height}_{$cropX}_{$cropY}.{$info->ext}";
// crop and resize the versioned image
$image = $this->Images->cropAndResizeImage($info->filepath, $width, $height, $cropWidth, $cropHeight, $cropX, $cropY);
// save this cropped image
$this->Images->saveImage($image, $croppedImagePath);
// remove temporary image file if there is one
if ($info->tempfile) {
unlink($info->tempfile);
}
// finally return this image path as a string so we can store it
return $this->MediaPaths->makeRelativePath($croppedImagePath);
}