本文整理汇总了PHP中ImageHelper::getAcceptedExtensions方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageHelper::getAcceptedExtensions方法的具体用法?PHP ImageHelper::getAcceptedExtensions怎么用?PHP ImageHelper::getAcceptedExtensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageHelper
的用法示例。
在下文中一共展示了ImageHelper::getAcceptedExtensions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateTransforms
/**
* Update the asset transforms for the FileModel.
*
* @param AssetFileModel $fileModel
* @param array|object|string $transformsToUpdate
* @return bool
*/
public function updateTransforms(AssetFileModel $fileModel, $transformsToUpdate)
{
if (!in_array(IOHelper::getExtension($fileModel->filename), ImageHelper::getAcceptedExtensions())) {
return true;
}
$sourceType = craft()->assetSources->getSourceTypeById($fileModel->sourceId);
$imageSource = $sourceType->getImageSourcePath($fileModel);
if (!IOHelper::fileExists($imageSource)) {
return false;
}
if (!is_array($transformsToUpdate)) {
$transformsToUpdate = array($transformsToUpdate);
}
foreach ($transformsToUpdate as $transform) {
$transform = $this->normalizeTransform($transform);
$transformLocation = $this->_getTransformLocation($transform);
$timeModified = $sourceType->getTimeTransformModified($fileModel, $transformLocation);
// Create the transform if the file doesn't exist, or if it was created before the image was last updated
// or if the transform dimensions have changed since it was last created
if (!$timeModified || $timeModified < $fileModel->dateModified || $timeModified < $transform->dimensionChangeTime) {
$targetFile = AssetsHelper::getTempFilePath(IOHelper::getExtension($fileModel->filename));
switch ($transform->mode) {
case 'fit':
craft()->images->loadImage($imageSource)->scaleToFit($transform->width, $transform->height)->saveAs($targetFile);
break;
case 'stretch':
craft()->images->loadImage($imageSource)->resize($transform->width, $transform->height)->saveAs($targetFile);
break;
default:
craft()->images->loadImage($imageSource)->scaleAndCrop($transform->width, $transform->height, true, $transform->position)->saveAs($targetFile);
break;
}
clearstatcache(true, $targetFile);
$sourceType->putImageTransform($fileModel, $transformLocation, $targetFile);
IOHelper::deleteFile($targetFile);
}
}
return true;
}
示例2: getUrlForFile
/**
* Get URL for a file.
*
* @param AssetFileModel $file
* @param $transform
* @return string
*/
public function getUrlForFile(AssetFileModel $file, $transform = null)
{
$returnPlaceholder = false;
if (!$transform || !in_array(IOHelper::getExtension($file->filename), ImageHelper::getAcceptedExtensions())) {
$sourceType = craft()->assetSources->getSourceTypeById($file->sourceId);
$base = $sourceType->getBaseUrl();
return $base . $file->getFolder()->fullPath . $file->filename;
}
// Get the transform index model
$existingTransformData = craft()->assetTransforms->getTransformIndex($file, $transform);
// Does the file actually exist?
if ($existingTransformData->fileExists) {
return craft()->assetTransforms->getUrlforTransformByFile($file, $transform);
} else {
// File doesn't exist yet - load the TransformLoader and set the placeholder URL flag
$placeholderUrl = UrlHelper::getResourceUrl('images/blank.gif');
if (!$this->_includedTransformLoader) {
$entityPlaceholderUrl = htmlspecialchars($placeholderUrl, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$spinnerUrl = UrlHelper::getResourceurl('images/spinner_transform.gif');
$actionUrl = UrlHelper::getActionUrl('assets/generateTransform');
craft()->templates->includeJsResource('js/TransformLoader.js');
craft()->templates->includeJs('new TransformLoader(' . JsonHelper::encode($placeholderUrl) . ', ' . JsonHelper::encode($entityPlaceholderUrl) . ', ' . JsonHelper::encode($spinnerUrl) . ', ' . JsonHelper::encode($actionUrl) . ');');
$this->_includedTransformLoader = true;
}
return $placeholderUrl . '#' . $existingTransformData->id;
}
}