/** * Saves an asset source. */ public function actionSaveTransform() { $this->requirePostRequest(); $transform = new AssetTransformModel(); $transform->id = craft()->request->getPost('transformId'); $transform->name = craft()->request->getPost('name'); $transform->handle = craft()->request->getPost('handle'); $transform->width = craft()->request->getPost('width'); $transform->height = craft()->request->getPost('height'); $transform->mode = craft()->request->getPost('mode'); $transform->position = craft()->request->getPost('position'); $transform->quality = craft()->request->getPost('quality'); $transform->format = craft()->request->getPost('format'); if (empty($transform->format)) { $transform->format = null; } $errors = false; if (empty($transform->width) && empty($transform->height)) { craft()->userSession->setError(Craft::t('You must set at least one of the dimensions.')); $errors = true; } if (!empty($transform->quality) && (!is_numeric($transform->quality) || $transform->quality > 100 || $transform->quality < 1)) { craft()->userSession->setError(Craft::t('Quality must be a number between 1 and 100 (included).')); $errors = true; } if (!empty($transform->format) && !in_array($transform->format, ImageHelper::getWebSafeFormats())) { craft()->userSession->setError(Craft::t('That is not an allowed format.')); $errors = true; } if (!$errors) { // Did it save? if (craft()->assetTransforms->saveTransform($transform)) { craft()->userSession->setNotice(Craft::t('Transform saved.')); $this->redirectToPostedUrl($transform); } else { craft()->userSession->setError(Craft::t('Couldn’t save source.')); } } // Send the transform back to the template craft()->urlManager->setRouteVariables(array('transform' => $transform)); }
/** * Return the thumbnail extension for a file. * * @param AssetFileModel $file * * @return string */ private function _getThumbExtension(AssetFileModel $file) { // For non-web-safe formats we go with jpg. if (!in_array(mb_strtolower(IOHelper::getExtension($file->filename)), ImageHelper::getWebSafeFormats())) { if ($file->getExtension() == 'svg' && craft()->images->isImagick()) { return 'png'; } return 'jpg'; } else { return $file->getExtension(); } }
/** * Return the thumbnail extension for a file. * * @param AssetFileModel $file * * @return string */ private function _getThumbExtension(AssetFileModel $file) { // For non-web-safe formats we go with jpg. if (!in_array(IOHelper::getExtension($file->filename), ImageHelper::getWebSafeFormats())) { return 'jpg'; } else { return $file->getExtension(); } }