private ImageInfo GetImageInfo(string imageUrl, Size targetSize) { var crop = _imageProcessor.GetCrop(imageUrl); if (crop != null) { return(new ImageInfo { Title = crop.Title, Description = crop.Description, ImageUrl = GetCropImageUrl(crop, targetSize) }); } MediaFile image = _imageProcessor.GetImage(imageUrl); if (image != null) { return(new ImageInfo { Title = image.Title, Description = image.Description, ImageUrl = GetFileImageUrl(image, targetSize) }); } return(null); }
public string Parse(ProductListTemplateData template, Product item) { if (template == null) { return(string.Empty); } string output = template.ProductTemplate; if (string.IsNullOrWhiteSpace(output)) { return(string.Empty); } MediaFile image = _imageProcessor.GetImage(item.DisplayImageUrl); output = ImageRegex.Replace(output, _urlHelper.ToAbsolute(_fileService.GetFileLocation(image, new Size { Width = 150, Height = 150 }))); output = NameRegex.Replace(output, item.Name ?? string.Empty); output = LinkRegex.Replace(output, item.AbsoluteUrl); output = PriceRegex.Replace(output, GetPrice(_productPricingMethod.GetDisplayPrice(item))); output = OldPriceRegex.Replace(output, GetPrice(_productPricingMethod.GetDisplayPreviousPrice(item))); return(output); }
public JsonResult GetImageData(string url) { var mediaFile = _imageProcessor.GetImage(url); return(mediaFile != null ? Json(new { alt = mediaFile.Title, title = mediaFile.Description }) : Json(new { alt = "", title = "" })); }
public string GetResizedImage(string imageUrl, Size size) { if (!string.IsNullOrEmpty(imageUrl)) { var mediaFile = _imageProcessor.GetImage(imageUrl); if (mediaFile != null) { return(_fileService.GetFileLocation(mediaFile, size)); } } return(string.Empty); }
public MvcHtmlString RenderImage(HtmlHelper helper, string imageUrl, Size targetSize = new Size(), string alt = null, string title = null, object attributes = null) { var cachingInfo = _mediaSettings.GetCachingInfo(imageUrl, targetSize, alt, title, attributes); return(helper.GetCached(cachingInfo, htmlHelper => { using (new SiteFilterDisabler(_session)) { if (string.IsNullOrWhiteSpace(imageUrl)) { return MvcHtmlString.Empty; } var image = _imageProcessor.GetImage(imageUrl); if (image == null) { return MvcHtmlString.Empty; } if (targetSize != default(Size) && ImageProcessor.RequiresResize(image.Size, targetSize)) { var location = _fileService.GetFileLocation(image, targetSize); if (!string.IsNullOrWhiteSpace(location)) { imageUrl = location; } } var tagBuilder = new TagBuilder("img"); tagBuilder.Attributes.Add("src", imageUrl); tagBuilder.Attributes.Add("alt", alt ?? image.Title); tagBuilder.Attributes.Add("title", title ?? image.Description); if (attributes != null) { var routeValueDictionary = MrCMSHtmlHelper.AnonymousObjectToHtmlAttributes(attributes); foreach (var kvp in routeValueDictionary) { tagBuilder.Attributes.Add(kvp.Key, kvp.Value.ToString()); } } return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.SelfClosing)); } })); }
private MediaFile GetImage(string url) { return(_imageProcessor.GetImage(url)); }