public function transformImage($image, $transform, $transformDefaults, $configOverrides)
{
if (!$image) {
return null;
// there's nothing to see here, move along.
}
$this->configModel = new Imager_ConfigModel($configOverrides);
$pathsModel = new Imager_ImagePathsModel($image);
$this->imagineInstance = $this->_createImagineInstance();
/**
* Check all the things that could go wrong(tm)
*/
if (!IOHelper::getRealPath($pathsModel->sourcePath)) {
throw new Exception(Craft::t('Source folder “{sourcePath}” does not exist', array('sourcePath' => $pathsModel->sourcePath)));
}
if (!IOHelper::getRealPath($pathsModel->targetPath)) {
IOHelper::createFolder($pathsModel->targetPath, craft()->config->get('defaultFolderPermissions'), true);
if (!IOHelper::getRealPath($pathsModel->targetPath)) {
throw new Exception(Craft::t('Target folder “{targetPath}” does not exist and could not be created', array('targetPath' => $pathsModel->targetPath)));
}
$pathsModel->targetPath = IOHelper::getRealPath($pathsModel->targetPath);
}
if ($pathsModel->targetPath && !IOHelper::isWritable($pathsModel->targetPath)) {
throw new Exception(Craft::t('Target folder “{targetPath}” is not writeable', array('targetPath' => $pathsModel->targetPath)));
}
if (!IOHelper::fileExists($pathsModel->sourcePath . $pathsModel->sourceFilename)) {
throw new Exception(Craft::t('Requested image “{fileName}” does not exist in path “{sourcePath}”', array('fileName' => $pathsModel->sourceFilename, 'sourcePath' => $pathsModel->sourcePath)));
}
if (!craft()->images->checkMemoryForImage($pathsModel->sourcePath . $pathsModel->sourceFilename)) {
throw new Exception(Craft::t("Not enough memory available to perform this image operation."));
}
/**
* Transform can be either an array or just an object.
* Act accordingly and return the results the same way to the template.
*/
$r = null;
if (isset($transform[0])) {
$transformedImages = array();
foreach ($transform as $t) {
$transformedImage = $this->_getTransformedImage($pathsModel, $transformDefaults != null ? array_merge($transformDefaults, $t) : $t);
$transformedImages[] = $transformedImage;
}
$r = $transformedImages;
} else {
$transformedImage = $this->_getTransformedImage($pathsModel, $transformDefaults != null ? array_merge($transformDefaults, (array) $transform) : $transform);
$r = $transformedImage;
}
$this->imageInstance = null;
/**
* If this was an ajax request, and optimization tasks were created, trigger them now.
*/
if (craft()->request->isAjaxRequest() && $this->taskCreated && $this->getSetting('runTasksImmediatelyOnAjaxRequests')) {
$this->_triggerTasksNow();
}
if (count($this->invalidatePaths) > 0) {
craft()->imager_aws->invalidateCloudfrontPaths($this->invalidatePaths);
$this->invalidatePaths = array();
}
return $r;
}