本文整理汇总了PHP中ImageHelper::getWebSafeFormats方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageHelper::getWebSafeFormats方法的具体用法?PHP ImageHelper::getWebSafeFormats怎么用?PHP ImageHelper::getWebSafeFormats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageHelper
的用法示例。
在下文中一共展示了ImageHelper::getWebSafeFormats方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionSaveTransform
/**
* 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));
}
示例2: _getThumbExtension
/**
* 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();
}
}
示例3: _getThumbExtension
/**
* 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();
}
}