public function actionGetCroppedImages() { // assign vars $this->requireAjaxRequest(); $this->requireAdmin(); $post = craft()->request->getPost(); $assetId = $post['assetId']; $entryId = $post['entryId']; $name = $post['name']; $entry = craft()->elements->getElementById($entryId); $sectionHandle = $entry->section->handle; $entryType = $entry->type->handle; $folder = craft()->imageCropper->getCropFolder(); $source = craft()->imageCropper->getCropSource(); // get dimensions from plugin settings - based on sectionHandle and entryType $dimensions = craft()->imageCropper->getDimensionsArray($sectionHandle, $entryType); // fetch the asset $asset = craft()->assets->getFileById($assetId); $context = new ImageCropper_ContextModel(); $context->setAttribute('asset', $asset); $context->setAttribute('entry', $entry); $context->setAttribute('cropSource', $source); $context->setAttribute('folder', $folder); $context->setAttribute('name', $name); $context->namespace = 'fields'; $context->cropType = CropType::Dimensions; $response = new ImageCropper_ResponseModel(); $htmlData = array(); foreach ($dimensions as $dimension) { $context->width = $dimension['width']; $context->height = $dimension['height']; // create image crops $cropResponse = craft()->imageCropper->getCrop($context); if ($cropResponse->isSuccess()) { $htmlData[] = $cropResponse->data; $response->setSuccessMessage($cropResponse->getMessage()); } else { $response->setErrorMessage($cropResponse->getMessage()); break; } } if ($response->isSuccess()) { $response->setSuccessMessage('Crops successfully generated.'); } $response->data = $htmlData; $this->returnJson($response); }
/** * Set attributes from an ImageCropper_ContextModel * @param ImageCropper_ContextModel $contextModel */ public function setAttributesByContext(ImageCropper_ContextModel $contextModel) { $this->setAttributes($contextModel->getAttributes()); }