/// <summary> /// Gets the underlying image processing service URL from the IPublishedContent item. /// </summary> /// <param name="mediaItem">The IPublishedContent item.</param> /// <param name="imageUrlGenerator">The image URL generator.</param> /// <param name="publishedValueFallback">The published value fallback.</param> /// <param name="publishedUrlProvider">The published URL provider.</param> /// <param name="width">The width of the output image.</param> /// <param name="height">The height of the output image.</param> /// <param name="propertyAlias">Property alias of the property containing the JSON data.</param> /// <param name="cropAlias">The crop alias.</param> /// <param name="quality">Quality percentage of the output image.</param> /// <param name="imageCropMode">The image crop mode.</param> /// <param name="imageCropAnchor">The image crop anchor.</param> /// <param name="preferFocalPoint">Use focal point, to generate an output image using the focal point instead of the predefined crop.</param> /// <param name="useCropDimensions">Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters.</param> /// <param name="cacheBuster">Add a serialized date of the last edit of the item to ensure client cache refresh when updated.</param> /// <param name="furtherOptions">These are any query string parameters (formatted as query strings) that ImageProcessor supports. For example: /// <example><![CDATA[ /// furtherOptions: "bgcolor=fff" /// ]]></example></param> /// <param name="urlMode">The url mode.</param> /// <returns> /// The URL of the cropped image. /// </returns> public static string?GetCropUrl( this IPublishedContent mediaItem, IImageUrlGenerator imageUrlGenerator, IPublishedValueFallback publishedValueFallback, IPublishedUrlProvider publishedUrlProvider, int?width = null, int?height = null, string propertyAlias = Cms.Core.Constants.Conventions.Media.File, string?cropAlias = null, int?quality = null, ImageCropMode?imageCropMode = null, ImageCropAnchor?imageCropAnchor = null, bool preferFocalPoint = false, bool useCropDimensions = false, bool cacheBuster = true, string?furtherOptions = null, UrlMode urlMode = UrlMode.Default) => mediaItem.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, null, false, width, height, propertyAlias, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, urlMode);
public GridPropertyEditor( IDataValueEditorFactory dataValueEditorFactory, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, HtmlImageSourceParser imageSourceParser, RichTextEditorPastedImages pastedImages, HtmlLocalLinkParser localLinkParser, IIOHelper ioHelper, IImageUrlGenerator imageUrlGenerator) : base(dataValueEditorFactory) { _backOfficeSecurityAccessor = backOfficeSecurityAccessor; _ioHelper = ioHelper; _imageSourceParser = imageSourceParser; _pastedImages = pastedImages; _localLinkParser = localLinkParser; _imageUrlGenerator = imageUrlGenerator; }
public RichTextPropertyValueEditor( DataEditorAttribute attribute, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, HtmlImageSourceParser imageSourceParser, HtmlLocalLinkParser localLinkParser, RichTextEditorPastedImages pastedImages, IImageUrlGenerator imageUrlGenerator, IJsonSerializer jsonSerializer, IIOHelper ioHelper, IHtmlSanitizer htmlSanitizer) : this(attribute, backOfficeSecurityAccessor, localizedTextService, shortStringHelper, imageSourceParser, localLinkParser, pastedImages, imageUrlGenerator, jsonSerializer, ioHelper, htmlSanitizer, StaticServiceProvider.Instance.GetRequiredService <IHtmlMacroParameterParser>()) { }
public UsersController( MediaFileManager mediaFileManager, IOptions <ContentSettings> contentSettings, IHostingEnvironment hostingEnvironment, ISqlContext sqlContext, IImageUrlGenerator imageUrlGenerator, IOptions <SecuritySettings> securitySettings, IEmailSender emailSender, IBackOfficeSecurityAccessor backofficeSecurityAccessor, AppCaches appCaches, IShortStringHelper shortStringHelper, IUserService userService, ILocalizedTextService localizedTextService, IUmbracoMapper umbracoMapper, IOptions <GlobalSettings> globalSettings, IBackOfficeUserManager backOfficeUserManager, ILoggerFactory loggerFactory, LinkGenerator linkGenerator, IBackOfficeExternalLoginProviders externalLogins, UserEditorAuthorizationHelper userEditorAuthorizationHelper, IPasswordChanger <BackOfficeIdentityUser> passwordChanger) : this(mediaFileManager, contentSettings, hostingEnvironment, sqlContext, imageUrlGenerator, securitySettings, emailSender, backofficeSecurityAccessor, appCaches, shortStringHelper, userService, localizedTextService, umbracoMapper, globalSettings, backOfficeUserManager, loggerFactory, linkGenerator, externalLogins, userEditorAuthorizationHelper, passwordChanger, StaticServiceProvider.Instance.GetRequiredService <IHttpContextAccessor>(), StaticServiceProvider.Instance.GetRequiredService <IOptions <WebRoutingSettings> >()) { }
public UsersController( MediaFileManager mediaFileManager, IOptions <ContentSettings> contentSettings, IHostingEnvironment hostingEnvironment, ISqlContext sqlContext, IImageUrlGenerator imageUrlGenerator, IOptions <SecuritySettings> securitySettings, IEmailSender emailSender, IBackOfficeSecurityAccessor backofficeSecurityAccessor, AppCaches appCaches, IShortStringHelper shortStringHelper, IUserService userService, ILocalizedTextService localizedTextService, IUmbracoMapper umbracoMapper, IOptions <GlobalSettings> globalSettings, IBackOfficeUserManager backOfficeUserManager, ILoggerFactory loggerFactory, LinkGenerator linkGenerator, IBackOfficeExternalLoginProviders externalLogins, UserEditorAuthorizationHelper userEditorAuthorizationHelper, IPasswordChanger <BackOfficeIdentityUser> passwordChanger) { _mediaFileManager = mediaFileManager; _contentSettings = contentSettings.Value; _hostingEnvironment = hostingEnvironment; _sqlContext = sqlContext; _imageUrlGenerator = imageUrlGenerator; _securitySettings = securitySettings.Value; _emailSender = emailSender; _backofficeSecurityAccessor = backofficeSecurityAccessor; _appCaches = appCaches; _shortStringHelper = shortStringHelper; _userService = userService; _localizedTextService = localizedTextService; _umbracoMapper = umbracoMapper; _globalSettings = globalSettings.Value; _userManager = backOfficeUserManager; _loggerFactory = loggerFactory; _linkGenerator = linkGenerator; _externalLogins = externalLogins; _userEditorAuthorizationHelper = userEditorAuthorizationHelper; _passwordChanger = passwordChanger; _logger = _loggerFactory.CreateLogger <UsersController>(); }
/// <summary> /// Gets the underlying image processing service URL from the image path. /// </summary> /// <param name="imageUrl">The image URL.</param> /// <param name="imageUrlGenerator">The image URL generator.</param> /// <param name="width">The width of the output image.</param> /// <param name="height">The height of the output image.</param> /// <param name="imageCropperValue">The Json data from the Umbraco Core Image Cropper property editor.</param> /// <param name="cropAlias">The crop alias.</param> /// <param name="quality">Quality percentage of the output image.</param> /// <param name="imageCropMode">The image crop mode.</param> /// <param name="imageCropAnchor">The image crop anchor.</param> /// <param name="preferFocalPoint"> /// Use focal point to generate an output image using the focal point instead of the /// predefined crop if there is one. /// </param> /// <param name="useCropDimensions"> /// Use crop dimensions to have the output image sized according to the predefined crop /// sizes, this will override the width and height parameters. /// </param> /// <param name="cacheBusterValue"> /// Add a serialized date of the last edit of the item to ensure client cache refresh when /// updated. /// </param> /// <param name="furtherOptions"> /// These are any query string parameters (formatted as query strings) that the underlying image processing service /// supports. For example: /// <example><![CDATA[ /// furtherOptions: "bgcolor=fff" /// ]]></example> /// </param> /// <returns> /// The URL of the cropped image. /// </returns> public static string?GetCropUrl( this string imageUrl, IImageUrlGenerator imageUrlGenerator, int?width = null, int?height = null, string?imageCropperValue = null, string?cropAlias = null, int?quality = null, ImageCropMode?imageCropMode = null, ImageCropAnchor?imageCropAnchor = null, bool preferFocalPoint = false, bool useCropDimensions = false, string?cacheBusterValue = null, string?furtherOptions = null) { if (string.IsNullOrWhiteSpace(imageUrl)) { return(null); } ImageCropperValue?cropDataSet = null; if (string.IsNullOrEmpty(imageCropperValue) == false && imageCropperValue.DetectIsJson() && (imageCropMode == ImageCropMode.Crop || imageCropMode == null)) { cropDataSet = imageCropperValue.DeserializeImageCropperValue(); } return(GetCropUrl( imageUrl, imageUrlGenerator, cropDataSet, width, height, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions)); }
public RichTextPropertyValueEditor( DataEditorAttribute attribute, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, HtmlImageSourceParser imageSourceParser, HtmlLocalLinkParser localLinkParser, RichTextEditorPastedImages pastedImages, IImageUrlGenerator imageUrlGenerator, IJsonSerializer jsonSerializer, IIOHelper ioHelper) : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) { _backOfficeSecurityAccessor = backOfficeSecurityAccessor; _imageSourceParser = imageSourceParser; _localLinkParser = localLinkParser; _pastedImages = pastedImages; _imageUrlGenerator = imageUrlGenerator; }
public BackOfficeServerVariables( LinkGenerator linkGenerator, IRuntimeState runtimeState, UmbracoFeatures features, IOptionsMonitor <GlobalSettings> globalSettings, IUmbracoVersion umbracoVersion, IOptionsMonitor <ContentSettings> contentSettings, IHttpContextAccessor httpContextAccessor, TreeCollection treeCollection, IHostingEnvironment hostingEnvironment, IOptionsMonitor <RuntimeSettings> runtimeSettings, IOptionsMonitor <SecuritySettings> securitySettings, IRuntimeMinifier runtimeMinifier, IBackOfficeExternalLoginProviders externalLogins, IImageUrlGenerator imageUrlGenerator, PreviewRoutes previewRoutes, IEmailSender emailSender, IOptionsMonitor <MemberPasswordConfigurationSettings> memberPasswordConfigurationSettings) { _linkGenerator = linkGenerator; _runtimeState = runtimeState; _features = features; _globalSettings = globalSettings.CurrentValue; _umbracoVersion = umbracoVersion; _contentSettings = contentSettings.CurrentValue ?? throw new ArgumentNullException(nameof(contentSettings)); _httpContextAccessor = httpContextAccessor; _treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection)); _hostingEnvironment = hostingEnvironment; _runtimeSettings = runtimeSettings.CurrentValue; _securitySettings = securitySettings.CurrentValue; _runtimeMinifier = runtimeMinifier; _externalLogins = externalLogins; _imageUrlGenerator = imageUrlGenerator; _previewRoutes = previewRoutes; _emailSender = emailSender; _memberPasswordConfigurationSettings = memberPasswordConfigurationSettings.CurrentValue; globalSettings.OnChange(x => _globalSettings = x); contentSettings.OnChange(x => _contentSettings = x); runtimeSettings.OnChange(x => _runtimeSettings = x); securitySettings.OnChange(x => _securitySettings = x); memberPasswordConfigurationSettings.OnChange(x => _memberPasswordConfigurationSettings = x); }
/// <summary> /// Gets the ImageProcessor URL from the IPublishedContent item. /// </summary> /// <param name="mediaItem"> /// The IPublishedContent item. /// </param> /// <param name="width"> /// The width of the output image. /// </param> /// <param name="height"> /// The height of the output image. /// </param> /// <param name="propertyAlias"> /// Property alias of the property containing the Json data. /// </param> /// <param name="cropAlias"> /// The crop alias. /// </param> /// <param name="quality"> /// Quality percentage of the output image. /// </param> /// <param name="imageCropMode"> /// The image crop mode. /// </param> /// <param name="imageCropAnchor"> /// The image crop anchor. /// </param> /// <param name="preferFocalPoint"> /// Use focal point, to generate an output image using the focal point instead of the predefined crop /// </param> /// <param name="useCropDimensions"> /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters. /// </param> /// <param name="cacheBuster"> /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated /// </param> /// <param name="furtherOptions"> /// These are any query string parameters (formatted as query strings) that ImageProcessor supports. For example: /// <example> /// <![CDATA[ /// furtherOptions: "&bgcolor=fff" /// ]]> /// </example> /// </param> /// <param name="ratioMode"> /// Use a dimension as a ratio /// </param> /// <param name="upScale"> /// If the image should be upscaled to requested dimensions /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string GetCropUrl( this IPublishedContent mediaItem, IImageUrlGenerator imageUrlGenerator, int?width = null, int?height = null, string propertyAlias = Constants.Conventions.Media.File, string cropAlias = null, int?quality = null, ImageCropMode?imageCropMode = null, ImageCropAnchor?imageCropAnchor = null, bool preferFocalPoint = false, bool useCropDimensions = false, bool cacheBuster = true, string furtherOptions = null, ImageCropRatioMode?ratioMode = null, bool upScale = true) { return(mediaItem.GetCropUrl(imageUrlGenerator, null, false, width, height, propertyAlias, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, ratioMode, upScale)); }
public LogController( MediaFileManager mediaFileSystem, IImageUrlGenerator imageUrlGenerator, IAuditService auditService, IUmbracoMapper umbracoMapper, IBackOfficeSecurityAccessor backofficeSecurityAccessor, IUserService userService, AppCaches appCaches, ISqlContext sqlContext) { _mediaFileManager = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); _imageUrlGenerator = imageUrlGenerator ?? throw new ArgumentNullException(nameof(imageUrlGenerator)); _auditService = auditService ?? throw new ArgumentNullException(nameof(auditService)); _umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper)); _backofficeSecurityAccessor = backofficeSecurityAccessor ?? throw new ArgumentNullException(nameof(backofficeSecurityAccessor)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); _sqlContext = sqlContext ?? throw new ArgumentNullException(nameof(sqlContext)); }
/// <summary> /// Gets the underlying image processing service URL from the MediaWithCrops item. /// </summary> /// <param name="mediaWithCrops">The MediaWithCrops item.</param> /// <param name="imageUrlGenerator">The image URL generator.</param> /// <param name="publishedValueFallback">The published value fallback.</param> /// <param name="publishedUrlProvider">The published URL provider.</param> /// <param name="width">The width of the output image.</param> /// <param name="height">The height of the output image.</param> /// <param name="propertyAlias">Property alias of the property containing the JSON data.</param> /// <param name="cropAlias">The crop alias.</param> /// <param name="quality">Quality percentage of the output image.</param> /// <param name="imageCropMode">The image crop mode.</param> /// <param name="imageCropAnchor">The image crop anchor.</param> /// <param name="preferFocalPoint"> /// Use focal point, to generate an output image using the focal point instead of the /// predefined crop. /// </param> /// <param name="useCropDimensions"> /// Use crop dimensions to have the output image sized according to the predefined crop /// sizes, this will override the width and height parameters. /// </param> /// <param name="cacheBuster"> /// Add a serialized date of the last edit of the item to ensure client cache refresh when /// updated. /// </param> /// <param name="furtherOptions"> /// These are any query string parameters (formatted as query strings) that ImageProcessor supports. For example: /// <example><![CDATA[ /// furtherOptions: "bgcolor=fff" /// ]]></example> /// </param> /// <param name="urlMode">The url mode.</param> /// <returns> /// The URL of the cropped image. /// </returns> public static string?GetCropUrl( this MediaWithCrops mediaWithCrops, IImageUrlGenerator imageUrlGenerator, IPublishedValueFallback publishedValueFallback, IPublishedUrlProvider publishedUrlProvider, int?width = null, int?height = null, string propertyAlias = Constants.Conventions.Media.File, string?cropAlias = null, int?quality = null, ImageCropMode?imageCropMode = null, ImageCropAnchor?imageCropAnchor = null, bool preferFocalPoint = false, bool useCropDimensions = false, bool cacheBuster = true, string?furtherOptions = null, UrlMode urlMode = UrlMode.Default) { if (mediaWithCrops == null) { throw new ArgumentNullException(nameof(mediaWithCrops)); } return(mediaWithCrops.Content.GetCropUrl( imageUrlGenerator, publishedValueFallback, publishedUrlProvider, mediaWithCrops.LocalCrops, false, width, height, propertyAlias, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, urlMode)); }
public GridPropertyEditor( IDataValueEditorFactory dataValueEditorFactory, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, HtmlImageSourceParser imageSourceParser, RichTextEditorPastedImages pastedImages, HtmlLocalLinkParser localLinkParser, IIOHelper ioHelper, IImageUrlGenerator imageUrlGenerator) : this( dataValueEditorFactory, backOfficeSecurityAccessor, imageSourceParser, pastedImages, localLinkParser, ioHelper, imageUrlGenerator, StaticServiceProvider.Instance.GetRequiredService <IHtmlMacroParameterParser>(), StaticServiceProvider.Instance.GetRequiredService <IEditorConfigurationParser>()) { }
/// <summary> /// The constructor will setup the property editor based on the attribute if one is found. /// </summary> public RichTextPropertyEditor( IDataValueEditorFactory dataValueEditorFactory, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, HtmlImageSourceParser imageSourceParser, HtmlLocalLinkParser localLinkParser, RichTextEditorPastedImages pastedImages, IIOHelper ioHelper, IImageUrlGenerator imageUrlGenerator, IHtmlMacroParameterParser macroParameterParser, IEditorConfigurationParser editorConfigurationParser) : base(dataValueEditorFactory) { _backOfficeSecurityAccessor = backOfficeSecurityAccessor; _imageSourceParser = imageSourceParser; _localLinkParser = localLinkParser; _pastedImages = pastedImages; _ioHelper = ioHelper; _imageUrlGenerator = imageUrlGenerator; _macroParameterParser = macroParameterParser; _editorConfigurationParser = editorConfigurationParser; }
public BackOfficeServerVariables( LinkGenerator linkGenerator, IRuntimeState runtimeState, UmbracoFeatures features, IOptionsMonitor <GlobalSettings> globalSettings, IUmbracoVersion umbracoVersion, IOptionsMonitor <ContentSettings> contentSettings, IHttpContextAccessor httpContextAccessor, TreeCollection treeCollection, IHostingEnvironment hostingEnvironment, IOptionsMonitor <RuntimeSettings> runtimeSettings, IOptionsMonitor <SecuritySettings> securitySettings, IRuntimeMinifier runtimeMinifier, IBackOfficeExternalLoginProviders externalLogins, IImageUrlGenerator imageUrlGenerator, PreviewRoutes previewRoutes, IEmailSender emailSender, IOptionsMonitor <MemberPasswordConfigurationSettings> memberPasswordConfigurationSettings) : this( linkGenerator, runtimeState, features, globalSettings, umbracoVersion, contentSettings, httpContextAccessor, treeCollection, hostingEnvironment, runtimeSettings, securitySettings, runtimeMinifier, externalLogins, imageUrlGenerator, previewRoutes, emailSender, memberPasswordConfigurationSettings, StaticServiceProvider.Instance.GetRequiredService <IOptionsMonitor <DataTypesSettings> >()) { }
/// <summary> /// Gets the value image url for a specified crop. /// </summary> public string GetCropUrl(string alias, IImageUrlGenerator imageUrlGenerator, bool useCropDimensions = true, bool useFocalPoint = false, string cacheBusterValue = null) { var crop = GetCrop(alias); // could not find a crop with the specified, non-empty, alias if (crop == null && !string.IsNullOrWhiteSpace(alias)) { return(null); } var options = GetCropBaseOptions(string.Empty, crop, string.IsNullOrWhiteSpace(alias), useFocalPoint); if (crop != null && useCropDimensions) { options.Width = crop.Width; options.Height = crop.Height; } options.CacheBusterValue = cacheBusterValue; return(imageUrlGenerator.GetImageUrl(options)); }
public GridPropertyValueEditor( IDataValueEditorFactory dataValueEditorFactory, DataEditorAttribute attribute, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, ILocalizedTextService localizedTextService, HtmlImageSourceParser imageSourceParser, RichTextEditorPastedImages pastedImages, IShortStringHelper shortStringHelper, IImageUrlGenerator imageUrlGenerator, IJsonSerializer jsonSerializer, IIOHelper ioHelper) : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) { _backOfficeSecurityAccessor = backOfficeSecurityAccessor; _imageSourceParser = imageSourceParser; _pastedImages = pastedImages; _richTextPropertyValueEditor = dataValueEditorFactory.Create <RichTextPropertyEditor.RichTextPropertyValueEditor>(attribute); _mediaPickerPropertyValueEditor = dataValueEditorFactory.Create <MediaPickerPropertyEditor.MediaPickerPropertyValueEditor>(attribute); _imageUrlGenerator = imageUrlGenerator; }
public UserMapDefinition( ILocalizedTextService textService, IUserService userService, IEntityService entityService, ISectionService sectionService, AppCaches appCaches, ActionCollection actions, IOptions <GlobalSettings> globalSettings, MediaFileManager mediaFileManager, IShortStringHelper shortStringHelper, IImageUrlGenerator imageUrlGenerator) { _sectionService = sectionService; _entityService = entityService; _userService = userService; _textService = textService; _actions = actions; _appCaches = appCaches; _globalSettings = globalSettings.Value; _mediaFileManager = mediaFileManager; _shortStringHelper = shortStringHelper; _imageUrlGenerator = imageUrlGenerator; }
public static string GetCropUrl( this MediaWithCrops mediaWithCrops, IImageUrlGenerator imageUrlGenerator, int?width = null, int?height = null, string propertyAlias = Constants.Conventions.Media.File, string cropAlias = null, int?quality = null, ImageCropMode?imageCropMode = null, ImageCropAnchor?imageCropAnchor = null, bool preferFocalPoint = false, bool useCropDimensions = false, bool cacheBuster = true, string furtherOptions = null, ImageCropRatioMode?ratioMode = null, bool upScale = true) { if (mediaWithCrops == null) { throw new ArgumentNullException(nameof(mediaWithCrops)); } return(mediaWithCrops.Content.GetCropUrl(imageUrlGenerator, mediaWithCrops.LocalCrops, false, width, height, propertyAlias, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, ratioMode, upScale)); }
/// <summary> /// Gets the ImageProcessor Url by the crop alias using the specified property containing the image cropper Json data on the IPublishedContent item. /// </summary> /// <param name="mediaItem"> /// The IPublishedContent item. /// </param> /// <param name="propertyAlias"> /// The property alias of the property containing the Json data e.g. umbracoFile /// </param> /// <param name="cropAlias"> /// The crop alias e.g. thumbnail /// </param> /// <returns> /// The ImageProcessor.Web Url. /// </returns> public static string GetCropUrl(this IPublishedContent mediaItem, string propertyAlias, string cropAlias, IImageUrlGenerator imageUrlGenerator) { return(mediaItem.GetCropUrl(imageUrlGenerator, propertyAlias: propertyAlias, cropAlias: cropAlias, useCropDimensions: true)); }
/// <summary> /// Gets the ImageProcessor Url from the image path. /// </summary> /// <param name="imageUrl"> /// The image url. /// </param> /// <param name="imageUrlGenerator"> /// The generator that will process all the options and the image URL to return a full image urls with all processing options appended /// </param> /// <param name="cropDataSet"></param> /// <param name="width"> /// The width of the output image. /// </param> /// <param name="height"> /// The height of the output image. /// </param> /// <param name="cropAlias"> /// The crop alias. /// </param> /// <param name="quality"> /// Quality percentage of the output image. /// </param> /// <param name="imageCropMode"> /// The image crop mode. /// </param> /// <param name="imageCropAnchor"> /// The image crop anchor. /// </param> /// <param name="preferFocalPoint"> /// Use focal point to generate an output image using the focal point instead of the predefined crop if there is one /// </param> /// <param name="useCropDimensions"> /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters /// </param> /// <param name="cacheBusterValue"> /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated /// </param> /// <param name="furtherOptions"> /// These are any query string parameters (formatted as query strings) that ImageProcessor supports. For example: /// <example> /// <![CDATA[ /// furtherOptions: "&bgcolor=fff" /// ]]> /// </example> /// </param> /// <param name="ratioMode"> /// Use a dimension as a ratio /// </param> /// <param name="upScale"> /// If the image should be upscaled to requested dimensions /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string GetCropUrl( this string imageUrl, IImageUrlGenerator imageUrlGenerator, ImageCropperValue cropDataSet, int?width = null, int?height = null, string cropAlias = null, int?quality = null, ImageCropMode?imageCropMode = null, ImageCropAnchor?imageCropAnchor = null, bool preferFocalPoint = false, bool useCropDimensions = false, string cacheBusterValue = null, string furtherOptions = null, ImageCropRatioMode?ratioMode = null, bool upScale = true, string animationProcessMode = null) { if (string.IsNullOrEmpty(imageUrl)) { return(string.Empty); } ImageUrlGenerationOptions options; if (cropDataSet != null && (imageCropMode == ImageCropMode.Crop || imageCropMode == null)) { var crop = cropDataSet.GetCrop(cropAlias); // if a crop was specified, but not found, return null if (crop == null && !string.IsNullOrWhiteSpace(cropAlias)) { return(null); } options = cropDataSet.GetCropBaseOptions(imageUrl, crop, string.IsNullOrWhiteSpace(cropAlias), preferFocalPoint); if (crop != null & useCropDimensions) { width = crop.Width; height = crop.Height; } // If a predefined crop has been specified & there are no coordinates & no ratio mode, but a width parameter has been passed we can get the crop ratio for the height if (crop != null && string.IsNullOrEmpty(cropAlias) == false && crop.Coordinates == null && ratioMode == null && width != null && height == null) { options.HeightRatio = (decimal)crop.Height / crop.Width; } // If a predefined crop has been specified & there are no coordinates & no ratio mode, but a height parameter has been passed we can get the crop ratio for the width if (crop != null && string.IsNullOrEmpty(cropAlias) == false && crop.Coordinates == null && ratioMode == null && width == null && height != null) { options.WidthRatio = (decimal)crop.Width / crop.Height; } } else { options = new ImageUrlGenerationOptions(imageUrl) { ImageCropMode = (imageCropMode ?? ImageCropMode.Pad).ToString().ToLowerInvariant(), ImageCropAnchor = imageCropAnchor?.ToString().ToLowerInvariant() }; } options.Quality = quality; options.Width = ratioMode != null && ratioMode.Value == ImageCropRatioMode.Width ? null : width; options.Height = ratioMode != null && ratioMode.Value == ImageCropRatioMode.Height ? null : height; options.AnimationProcessMode = animationProcessMode; if (ratioMode == ImageCropRatioMode.Width && height != null) { // if only height specified then assume a square if (width == null) { width = height; } options.WidthRatio = (decimal)width / (decimal)height; } if (ratioMode == ImageCropRatioMode.Height && width != null) { // if only width specified then assume a square if (height == null) { height = width; } options.HeightRatio = (decimal)height / (decimal)width; } options.UpScale = upScale; options.FurtherOptions = furtherOptions; options.CacheBusterValue = cacheBusterValue; return(imageUrlGenerator.GetImageUrl(options)); }
public static string GetLocalCropUrl(this MediaWithCrops mediaWithCrops, string alias, IImageUrlGenerator imageUrlGenerator, string cacheBusterValue) { return(mediaWithCrops.LocalCrops.Src + mediaWithCrops.LocalCrops.GetCropUrl(alias, imageUrlGenerator, cacheBusterValue: cacheBusterValue)); }
public static string GetCropUrl(this IPublishedContent mediaItem, string cropAlias, IImageUrlGenerator imageUrlGenerator, ImageCropperValue imageCropperValue) { return(mediaItem.Url().GetCropUrl(imageUrlGenerator, imageCropperValue, cropAlias: cropAlias, useCropDimensions: true)); }
internal static IActionResult PostSetAvatarInternal(IList <IFormFile> files, IUserService userService, IAppCache cache, MediaFileManager mediaFileManager, IShortStringHelper shortStringHelper, ContentSettings contentSettings, IHostingEnvironment hostingEnvironment, IImageUrlGenerator imageUrlGenerator, int id) { if (files is null) { return(new UnsupportedMediaTypeResult()); } var root = hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempFileUploads); //ensure it exists Directory.CreateDirectory(root); //must have a file if (files.Count == 0) { return(new NotFoundResult()); } var user = userService.GetUserById(id); if (user == null) { return(new NotFoundResult()); } if (files.Count > 1) { return(new ValidationErrorResult("The request was not formatted correctly, only one file can be attached to the request")); } //get the file info var file = files.First(); var fileName = file.FileName.Trim(new[] { '\"' }).TrimEnd(); var safeFileName = fileName.ToSafeFileName(shortStringHelper); var ext = safeFileName.Substring(safeFileName.LastIndexOf('.') + 1).ToLower(); if (contentSettings.DisallowedUploadFiles.Contains(ext) == false) { //generate a path of known data, we don't want this path to be guessable user.Avatar = "UserAvatars/" + (user.Id + safeFileName).GenerateHash <SHA1>() + "." + ext; using (var fs = file.OpenReadStream()) { mediaFileManager.FileSystem.AddFile(user.Avatar, fs, true); } userService.Save(user); } return(new OkObjectResult(user.GetUserAvatarUrls(cache, mediaFileManager, imageUrlGenerator))); }
public static string GetCropUrl(this IPublishedContent mediaItem, string cropAlias, IImageUrlGenerator imageUrlGenerator, ImageCropperValue imageCropperValue) { return(mediaItem.GetCropUrl(imageCropperValue, cropAlias, imageUrlGenerator)); }
public ImageUrlGeneratorController(IImageUrlGenerator imageUrlGenerator) { _imageUrlGenerator = imageUrlGenerator; }
/// <summary> /// Used by the RTE (and grid RTE) for drag/drop/persisting images /// </summary> /// <param name="html"></param> /// <param name="mediaParentFolder"></param> /// <param name="userId"></param> /// <returns></returns> internal string FindAndPersistPastedTempImages(string html, Guid mediaParentFolder, int userId, IImageUrlGenerator imageUrlGenerator) { // Find all img's that has data-tmpimg attribute // Use HTML Agility Pack - https://html-agility-pack.net var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var tmpImages = htmlDoc.DocumentNode.SelectNodes($"//img[@{TemporaryImageDataAttribute}]"); if (tmpImages == null || tmpImages.Count == 0) { return(html); } // An array to contain a list of URLs that // we have already processed to avoid dupes var uploadedImages = new Dictionary <string, GuidUdi>(); foreach (var img in tmpImages) { // The data attribute contains the path to the tmp img to persist as a media item var tmpImgPath = img.GetAttributeValue(TemporaryImageDataAttribute, string.Empty); if (string.IsNullOrEmpty(tmpImgPath)) { continue; } var absoluteTempImagePath = IOHelper.MapPath(tmpImgPath); var fileName = Path.GetFileName(absoluteTempImagePath); var safeFileName = fileName.ToSafeFileName(); var mediaItemName = safeFileName.ToFriendlyName(); IMedia mediaFile; GuidUdi udi; if (uploadedImages.ContainsKey(tmpImgPath) == false) { if (mediaParentFolder == Guid.Empty) { mediaFile = _mediaService.CreateMedia(mediaItemName, Constants.System.Root, Constants.Conventions.MediaTypes.Image, userId); } else { mediaFile = _mediaService.CreateMedia(mediaItemName, mediaParentFolder, Constants.Conventions.MediaTypes.Image, userId); } var fileInfo = new FileInfo(absoluteTempImagePath); var fileStream = fileInfo.OpenReadWithRetry(); if (fileStream == null) { throw new InvalidOperationException("Could not acquire file stream"); } using (fileStream) { mediaFile.SetValue(_contentTypeBaseServiceProvider, Constants.Conventions.Media.File, safeFileName, fileStream); } _mediaService.Save(mediaFile, userId); udi = mediaFile.GetUdi(); } else { // Already been uploaded & we have it's UDI udi = uploadedImages[tmpImgPath]; } // Add the UDI to the img element as new data attribute img.SetAttributeValue("data-udi", udi.ToString()); // Get the new persisted image URL var mediaTyped = _umbracoContextAccessor?.UmbracoContext?.Media.GetById(udi.Guid); if (mediaTyped == null) { throw new PanicException($"Could not find media by id {udi.Guid} or there was no UmbracoContext available."); } var location = mediaTyped.Url(); // Find the width & height attributes as we need to set the imageprocessor QueryString var width = img.GetAttributeValue("width", int.MinValue); var height = img.GetAttributeValue("height", int.MinValue); if (width != int.MinValue && height != int.MinValue) { location = imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(location) { ImageCropMode = "max", Width = width, Height = height }); } img.SetAttributeValue("src", location); // Remove the data attribute (so we do not re-process this) img.Attributes.Remove(TemporaryImageDataAttribute); // Add to the dictionary to avoid dupes if (uploadedImages.ContainsKey(tmpImgPath) == false) { uploadedImages.Add(tmpImgPath, udi); // Delete folder & image now its saved in media // The folder should contain one image - as a unique guid folder created // for each image uploaded from TinyMceController var folderName = Path.GetDirectoryName(absoluteTempImagePath); try { Directory.Delete(folderName, true); } catch (Exception ex) { _logger.Error <string>(typeof(HtmlImageSourceParser), ex, "Could not delete temp file or folder {FileName}", absoluteTempImagePath); } } } return(htmlDoc.DocumentNode.OuterHtml); }
public ImagesController(IMediaFileSystem mediaFileSystem, IContentSection contentSection, IImageUrlGenerator imageUrlGenerator) { _mediaFileSystem = mediaFileSystem; _contentSection = contentSection; _imageUrlGenerator = imageUrlGenerator; }
private static string?GetCropUrl( this IPublishedContent mediaItem, IImageUrlGenerator imageUrlGenerator, IPublishedValueFallback publishedValueFallback, IPublishedUrlProvider publishedUrlProvider, ImageCropperValue?localCrops, bool localCropsOnly, int?width = null, int?height = null, string propertyAlias = Constants.Conventions.Media.File, string?cropAlias = null, int?quality = null, ImageCropMode?imageCropMode = null, ImageCropAnchor?imageCropAnchor = null, bool preferFocalPoint = false, bool useCropDimensions = false, bool cacheBuster = true, string?furtherOptions = null, UrlMode urlMode = UrlMode.Default) { if (mediaItem == null) { throw new ArgumentNullException(nameof(mediaItem)); } if (mediaItem.HasProperty(propertyAlias) == false || mediaItem.HasValue(propertyAlias) == false) { return(null); } var mediaItemUrl = mediaItem.MediaUrl(publishedUrlProvider, propertyAlias: propertyAlias, mode: urlMode); // Only get crops from media when required and used if (localCropsOnly == false && (imageCropMode == ImageCropMode.Crop || imageCropMode == null)) { // Get the default cropper value from the value converter var cropperValue = mediaItem.Value(publishedValueFallback, propertyAlias); var mediaCrops = cropperValue as ImageCropperValue; if (mediaCrops == null && cropperValue is JObject jobj) { mediaCrops = jobj.ToObject <ImageCropperValue>(); } if (mediaCrops == null && cropperValue is string imageCropperValue && string.IsNullOrEmpty(imageCropperValue) == false && imageCropperValue.DetectIsJson()) { mediaCrops = imageCropperValue.DeserializeImageCropperValue(); } // Merge crops if (localCrops == null) { localCrops = mediaCrops; } else if (mediaCrops != null) { localCrops = localCrops.Merge(mediaCrops); } } var cacheBusterValue = cacheBuster ? mediaItem.UpdateDate.ToFileTimeUtc().ToString(CultureInfo.InvariantCulture) : null; return(GetCropUrl( mediaItemUrl, imageUrlGenerator, localCrops, width, height, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions)); }
/// <summary> /// Gets the underlying image processing service URL from the image path. /// </summary> /// <param name="imageUrl">The image URL.</param> /// <param name="imageUrlGenerator"> /// The generator that will process all the options and the image URL to return a full /// image URLs with all processing options appended. /// </param> /// <param name="cropDataSet">The crop data set.</param> /// <param name="width">The width of the output image.</param> /// <param name="height">The height of the output image.</param> /// <param name="cropAlias">The crop alias.</param> /// <param name="quality">Quality percentage of the output image.</param> /// <param name="imageCropMode">The image crop mode.</param> /// <param name="imageCropAnchor">The image crop anchor.</param> /// <param name="preferFocalPoint"> /// Use focal point to generate an output image using the focal point instead of the /// predefined crop if there is one. /// </param> /// <param name="useCropDimensions"> /// Use crop dimensions to have the output image sized according to the predefined crop /// sizes, this will override the width and height parameters. /// </param> /// <param name="cacheBusterValue"> /// Add a serialized date of the last edit of the item to ensure client cache refresh when /// updated. /// </param> /// <param name="furtherOptions"> /// These are any query string parameters (formatted as query strings) that the underlying image processing service /// supports. For example: /// <example><![CDATA[ /// furtherOptions: "bgcolor=fff" /// ]]></example> /// </param> /// <returns> /// The URL of the cropped image. /// </returns> public static string?GetCropUrl( this string imageUrl, IImageUrlGenerator imageUrlGenerator, ImageCropperValue?cropDataSet, int?width = null, int?height = null, string?cropAlias = null, int?quality = null, ImageCropMode?imageCropMode = null, ImageCropAnchor?imageCropAnchor = null, bool preferFocalPoint = false, bool useCropDimensions = false, string?cacheBusterValue = null, string?furtherOptions = null) { if (string.IsNullOrWhiteSpace(imageUrl)) { return(null); } ImageUrlGenerationOptions options; if (cropDataSet != null && (imageCropMode == ImageCropMode.Crop || imageCropMode == null)) { ImageCropperValue.ImageCropperCrop?crop = cropDataSet.GetCrop(cropAlias); // If a crop was specified, but not found, return null if (crop == null && !string.IsNullOrWhiteSpace(cropAlias)) { return(null); } options = cropDataSet.GetCropBaseOptions(imageUrl, crop, preferFocalPoint || string.IsNullOrWhiteSpace(cropAlias)); if (crop != null && useCropDimensions) { width = crop.Width; height = crop.Height; } // Calculate missing dimension if a predefined crop has been specified, but has no coordinates if (crop != null && string.IsNullOrEmpty(cropAlias) == false && crop.Coordinates == null) { if (width != null && height == null) { height = (int)MathF.Round(width.Value * ((float)crop.Height / crop.Width)); } else if (width == null && height != null) { width = (int)MathF.Round(height.Value * ((float)crop.Width / crop.Height)); } } } else { options = new ImageUrlGenerationOptions(imageUrl) { ImageCropMode = imageCropMode ?? ImageCropMode.Pad, // Not sure why we default to Pad ImageCropAnchor = imageCropAnchor, }; } options.Quality = quality; options.Width = width; options.Height = height; options.FurtherOptions = furtherOptions; options.CacheBusterValue = cacheBusterValue; return(imageUrlGenerator.GetImageUrl(options)); }
public static string GetCropUrl(this MediaWithCrops mediaWithCrops, string propertyAlias, string cropAlias, IImageUrlGenerator imageUrlGenerator) { return(mediaWithCrops.GetCropUrl(imageUrlGenerator, propertyAlias: propertyAlias, cropAlias: cropAlias, useCropDimensions: true)); }