private void AddImage(IEntryImageInformation imageInfo, ImageSize size) { using (var stream = ResourceHelper.TestImage()) { _imageStore.Write(imageInfo, size, stream); } }
/// <summary> /// Returns an URL to entry thumbnail image. /// Currently only used for album and artist main images. /// /// Gets the URL to the static images folder on disk if possible, /// otherwise gets the image from the DB. /// </summary> /// <param name="urlHelper">URL helper. Cannot be null.</param> /// <param name="imageInfo">Image information. Cannot be null.</param> /// <param name="size">Requested image size.</param> /// <param name="fullUrl"> /// Whether the URL should always include the hostname and application path root. /// If this is false (default), the URL maybe either full (such as http://vocadb.net/Album/CoverPicture/123) /// or relative (such as /Album/CoverPicture/123). /// Usually this should be set to true if the image is to be referred from another domain. /// </param> /// <returns>URL to the image thumbnail.</returns> public static string ImageThumb(this UrlHelper urlHelper, IEntryImageInformation imageInfo, ImageSize size, bool fullUrl = false) { if (imageInfo == null) return null; var shouldExist = ShouldExist(imageInfo); string dynamicUrl = null; // Use MVC dynamic actions when requesting original or an image that doesn't exist on disk. if (imageInfo.EntryType == EntryType.Album) { if (size == ImageSize.Original) dynamicUrl = urlHelper.Action("CoverPicture", "Album", new { id = imageInfo.Id, v = imageInfo.Version }); else if (shouldExist && !imagePersister.HasImage(imageInfo, size)) dynamicUrl = urlHelper.Action("CoverPictureThumb", "Album", new { id = imageInfo.Id, v = imageInfo.Version }); } else if (imageInfo.EntryType == EntryType.Artist) { if (size == ImageSize.Original) dynamicUrl = urlHelper.Action("Picture", "Artist", new { id = imageInfo.Id, v = imageInfo.Version }); else if (shouldExist && !imagePersister.HasImage(imageInfo, size)) dynamicUrl = urlHelper.Action("PictureThumb", "Artist", new { id = imageInfo.Id, v = imageInfo.Version }); } if (dynamicUrl != null) { return (fullUrl ? AppConfig.HostAddress + dynamicUrl : dynamicUrl); } if (!shouldExist) return GetUnknownImageUrl(urlHelper, imageInfo); return imagePersister.GetUrlAbsolute(imageInfo, size, WebHelper.IsSSL(HttpContext.Current.Request)); }
public override bool IsSupported(IEntryImageInformation picture, ImageSize size) { return(picture.EntryType == EntryType.ReleaseEvent || picture.EntryType == EntryType.ReleaseEventSeries || ((picture.EntryType == EntryType.Artist || picture.EntryType == EntryType.Album) && picture.PurposeMainOrUnspecified() && size != ImageSize.Original)); }
private string GetRelativeUrl(IEntryImageInformation picture, ImageSize size) { if (picture.Version > 0) { return string.Format("/img/{0}/main{1}/{2}{3}?v={4}", picture.EntryType.ToString().ToLowerInvariant(), GetDir(size), picture.Id, ImageHelper.GetExtensionFromMime(picture.Mime), picture.Version); } else return string.Format("/img/{0}/main{1}/{2}{3}", picture.EntryType.ToString().ToLowerInvariant(), GetDir(size), picture.Id, ImageHelper.GetExtensionFromMime(picture.Mime)); }
public void Write(IEntryImageInformation picture, ImageSize size, Image image) { using (var stream = new MemoryStream()) { image.Save(stream, GetImageFormat(picture)); Write(picture, size, stream); } }
/// <summary> /// Initializes image data. /// </summary> /// <param name="image">Image information. Cannot be null.</param> /// <param name="thumbPersister">Thumb persister. Cannot be null.</param> /// <param name="ssl">Whether to generate SSL URLs.</param> /// <param name="sizes">Sizes to generate. If Nothing, no image URLs will be generated.</param> public EntryThumbForApiContract(IEntryImageInformation image, IEntryImagePersister thumbPersister, bool ssl, ImageSizes sizes = ImageSizes.All) { ParamIs.NotNull(() => image); ParamIs.NotNull(() => thumbPersister); if (string.IsNullOrEmpty(image.Mime) && sizes != ImageSizes.Nothing) { return; } if (sizes.HasFlag(ImageSizes.SmallThumb)) { UrlSmallThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.SmallThumb, ssl); } if (sizes.HasFlag(ImageSizes.Thumb)) { UrlThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.Thumb, ssl); } if (sizes.HasFlag(ImageSizes.TinyThumb)) { UrlTinyThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.TinyThumb, ssl); } }
public void GenerateThumbsAndMoveImage(Stream input, IEntryImageInformation imageInfo, ImageSizes imageSizes, int originalSize = Unlimited) { using (var original = ImageHelper.OpenImage(input)) { if (imageSizes.HasFlag(ImageSizes.Original)) { GenerateThumbAndMoveImage(original, input, imageInfo, ImageSize.Original, originalSize); } if (imageSizes.HasFlag(ImageSizes.Thumb)) { GenerateThumbAndMoveImage(original, input, imageInfo, ImageSize.Thumb, ImageHelper.DefaultThumbSize); } if (imageSizes.HasFlag(ImageSizes.SmallThumb)) { GenerateThumbAndMoveImage(original, input, imageInfo, ImageSize.SmallThumb, ImageHelper.DefaultSmallThumbSize); } if (imageSizes.HasFlag(ImageSizes.TinyThumb)) { GenerateThumbAndMoveImage(original, input, imageInfo, ImageSize.TinyThumb, ImageHelper.DefaultTinyThumbSize); } } }
public EntryThumbForApiContract(IEntryImageInformation image, IAggregatedEntryImageUrlFactory thumbPersister, ImageSizes sizes = ImageSizes.All) { ParamIs.NotNull(() => image); ParamIs.NotNull(() => thumbPersister); Mime = image.Mime; if (string.IsNullOrEmpty(image.Mime) && sizes != ImageSizes.Nothing) { return; } if (sizes.HasFlag(ImageSizes.Original)) { UrlOriginal = thumbPersister.GetUrlAbsolute(image, ImageSize.Original); } if (sizes.HasFlag(ImageSizes.SmallThumb)) { UrlSmallThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.SmallThumb); } if (sizes.HasFlag(ImageSizes.Thumb)) { UrlThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.Thumb); } if (sizes.HasFlag(ImageSizes.TinyThumb)) { UrlTinyThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.TinyThumb); } }
public VocaDbUrl GetUrl(IEntryImageInformation imageInfo, ImageSize size) { var urlHelper = urlHelperAccessor.Value; string dynamicUrl = null; if (imageInfo.EntryType == EntryType.Album) { if (size == ImageSize.Original) { dynamicUrl = urlHelper.Action("CoverPicture", "Album", new { id = imageInfo.Id, v = imageInfo.Version }); } else { dynamicUrl = urlHelper.Action("CoverPictureThumb", "Album", new { id = imageInfo.Id, v = imageInfo.Version }); } } else if (imageInfo.EntryType == EntryType.Artist) { if (size == ImageSize.Original) { dynamicUrl = urlHelper.Action("Picture", "Artist", new { id = imageInfo.Id, v = imageInfo.Version }); } else { dynamicUrl = urlHelper.Action("PictureThumb", "Artist", new { id = imageInfo.Id, v = imageInfo.Version }); } } return(!string.IsNullOrEmpty(dynamicUrl) ? new VocaDbUrl(dynamicUrl, UrlDomain.Main, System.UriKind.Relative) : VocaDbUrl.Empty); }
public static byte[] ReadBytes(this IEntryImagePersister persister, IEntryImageInformation imageInfo, ImageSize size) { using (var stream = persister.GetReadStream(imageInfo, size)) { return(StreamHelper.ReadStream(stream)); } }
/// <summary> /// Returns an URL to entry thumbnail image. /// Currently only used for album and artist main images. /// /// Gets the URL to the static images folder on disk if possible, /// otherwise gets the image from the DB. /// </summary> /// <param name="urlHelper">URL helper. Cannot be null.</param> /// <param name="imageInfo">Image information. Cannot be null.</param> /// <param name="size">Requested image size.</param> /// <param name="fullUrl"> /// Whether the URL should always include the hostname and application path root. /// If this is false (default), the URL maybe either full (such as http://vocadb.net/Album/CoverPicture/123) /// or relative (such as /Album/CoverPicture/123). /// Usually this should be set to true if the image is to be referred from another domain. /// </param> /// <param name="useUnknownImage">Use unknown image as fallback if image does not exist.</param> /// <returns>URL to the image thumbnail.</returns> public static string ImageThumb(this UrlHelper urlHelper, IEntryImageInformation imageInfo, ImageSize size, bool fullUrl = false, bool useUnknownImage = true) { var unknown = useUnknownImage ? GetUnknownImageUrl(urlHelper) : VocaDbUrl.Empty; var url = ImageUrlFactory.GetUrlWithFallback(imageInfo, size, unknown).ToAbsoluteIfNotMain(); return(fullUrl ? url.ToAbsolute().Url : url.Url); }
public VocaDbUrl GetUrl(IEntryImageInformation imageInfo, ImageSize size) { // Logic: try to get URL from source where it exists. // If it seems the file doesn't exist, try a secondary source and finally fall back to accepting source where the file doesn't exist. return(FactoriesCheckExist(imageInfo, size).Select(f => f.GetUrl(imageInfo, size)).FirstOrDefault() ?? Factories(imageInfo, size).Select(f => f.GetUrl(imageInfo, size)).FirstOrDefault() ?? throw new ArgumentException($"Could not find URL factory for {imageInfo}", nameof(imageInfo))); }
private void AssertDimensions(IEntryImageInformation imageInfo, ImageSize size, int width, int height) { using (var stream = persister.GetReadStream(imageInfo, size)) using (var img = Image.FromStream(stream)) { Assert.AreEqual(width, img.Width, "Image width"); Assert.AreEqual(height, img.Height, "Image height"); } }
public void Write(IEntryImageInformation picture, ImageSize size, Stream stream) { var bytes = StreamHelper.ReadStream(stream); var url = GetUrl(picture, size).Url; images[url] = bytes; }
private void AssertDimensions(IEntryImageInformation imageInfo, ImageSize size, int width, int height) { using (var stream = _persister.GetReadStream(imageInfo, size)) using (var img = Image.FromStream(stream)) { img.Width.Should().Be(width, "Image width"); img.Height.Should().Be(height, "Image height"); } }
public EntryThumbForApiContract(IEntryImageInformation image, IEntryImagePersister thumbPersister, bool ssl) { if (!string.IsNullOrEmpty(image.Mime)) { UrlSmallThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.SmallThumb, ssl); UrlThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.Thumb, ssl); UrlTinyThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.TinyThumb, ssl); } }
public static string GetUrlAbsolute(this IEntryImagePersister persister, IEntryImageInformation picture, ImageSize size, bool checkExists) { if (checkExists && !persister.HasImage(picture, size)) { return(null); } return(persister.GetUrlAbsolute(picture, size)); }
public static VocaDbUrl GetUrl(this IEntryImageUrlFactory persister, IEntryImageInformation picture, ImageSize size, bool checkExists) { if (checkExists && !persister.HasImage(picture, size)) { return(VocaDbUrl.Empty); } return(persister.GetUrl(picture, size)); }
public static EntryThumbForApiContract Create(IEntryImageInformation image, IAggregatedEntryImageUrlFactory thumbPersister, ImageSizes sizes = ImageSizes.All) { if (thumbPersister == null || string.IsNullOrEmpty(image?.Mime)) { return(null); } return(new EntryThumbForApiContract(image, thumbPersister, sizes)); }
public override string GetPath(IEntryImageInformation picture, ImageSize size) { if (string.IsNullOrEmpty(staticRoot)) { return(string.Empty); } var relative = string.Format(@"img\{0}\main{1}\{2}{3}", picture.EntryType, GetDir(size), picture.Id, ImageHelper.GetExtensionFromMime(picture.Mime)); return(Path.Combine(staticRoot, relative)); }
/// <summary> /// Writes an image to a file, overwriting any existing file. /// /// If the dimensions of the original image are smaller or equal than the thumbnail size, /// the file is simply copied. Otherwise it will be shrunk. /// </summary> /// <param name="original">Original image. Cannot be null.</param> /// <param name="input">Stream to be written. Cannot be null.</param> /// <param name="imageInfo">Image information. Cannot be null.</param> /// <param name="size">Image size of the saved thumbnail.</param> /// <param name="dimensions">Dimensions of the thumbnail.</param> private void GenerateThumbAndMoveImage(Image original, Stream input, IEntryImageInformation imageInfo, ImageSize size, int dimensions) { if (dimensions != Unlimited && (original.Width > dimensions || original.Height > dimensions)) { using (var thumb = ImageHelper.ResizeToFixedSize(original, dimensions, dimensions)) { persister.Write(imageInfo, size, thumb); } } else { persister.Write(imageInfo, size, input); } }
public void Write(IEntryImageInformation picture, ImageSize size, Image image) { var path = GetPath(picture, size); if (string.IsNullOrEmpty(path)) return; EnsureDirExistsForFile(path); image.Save(path); }
public void Write(IEntryImageInformation picture, ImageSize size, Stream stream) { var bytes = StreamHelper.ReadStream(stream); var url = GetUrlAbsolute(picture, size, false); if (images.ContainsKey(url)) images[url] = bytes; else images.Add(url, bytes); }
private string GetRelativeUrl(IEntryImageInformation picture, ImageSize size) { if (picture.Version > 0) { return(string.Format("/img/{0}/main{1}/{2}{3}?v={4}", picture.EntryType.ToString().ToLowerInvariant(), GetDir(size), picture.Id, ImageHelper.GetExtensionFromMime(picture.Mime), picture.Version)); } else { return(string.Format("/img/{0}/main{1}/{2}{3}", picture.EntryType.ToString().ToLowerInvariant(), GetDir(size), picture.Id, ImageHelper.GetExtensionFromMime(picture.Mime))); } }
public void Write(IEntryImageInformation picture, ImageSize size, Image image) { var path = GetPath(picture, size); if (string.IsNullOrEmpty(path)) { return; } EnsureDirExistsForFile(path); image.Save(path); }
/// <summary> /// Returns an URL to entry thumbnail image. /// Currently only used for album and artist main images. /// /// Gets the URL to the static images folder on disk if possible, /// otherwise gets the image from the DB. /// </summary> /// <param name="urlHelper">URL helper. Cannot be null.</param> /// <param name="imageInfo">Image information. Cannot be null.</param> /// <param name="size">Requested image size.</param> /// <param name="fullUrl"> /// Whether the URL should always include the hostname and application path root. /// If this is false (default), the URL maybe either full (such as http://vocadb.net/Album/CoverPicture/123) /// or relative (such as /Album/CoverPicture/123). /// Usually this should be set to true if the image is to be referred from another domain. /// </param> /// <returns>URL to the image thumbnail.</returns> public static string ImageThumb(this UrlHelper urlHelper, IEntryImageInformation imageInfo, ImageSize size, bool fullUrl = false) { if (imageInfo == null) { return(null); } var shouldExist = ShouldExist(imageInfo); string dynamicUrl = null; // Use MVC dynamic actions (instead of static file) when requesting original or an image that doesn't exist on disk. if (imageInfo.EntryType == EntryType.Album) { if (size == ImageSize.Original) { dynamicUrl = urlHelper.Action("CoverPicture", "Album", new { id = imageInfo.Id, v = imageInfo.Version }); } else if (shouldExist && !imagePersister.HasImage(imageInfo, size)) { dynamicUrl = urlHelper.Action("CoverPictureThumb", "Album", new { id = imageInfo.Id, v = imageInfo.Version }); } } else if (imageInfo.EntryType == EntryType.Artist) { if (size == ImageSize.Original) { dynamicUrl = urlHelper.Action("Picture", "Artist", new { id = imageInfo.Id, v = imageInfo.Version }); } else if (shouldExist && !imagePersister.HasImage(imageInfo, size)) { dynamicUrl = urlHelper.Action("PictureThumb", "Artist", new { id = imageInfo.Id, v = imageInfo.Version }); } } var ssl = WebHelper.IsSSL(HttpContext.Current.Request); if (dynamicUrl != null) { return(fullUrl ? VocaUriBuilder.Absolute(dynamicUrl, ssl) : dynamicUrl); } if (!shouldExist) { var unknown = GetUnknownImageUrl(urlHelper, imageInfo); return(fullUrl ? VocaUriBuilder.Absolute(unknown, ssl) : unknown); } // For all other cases use the static file return(imagePersister.GetUrlAbsolute(imageInfo, size, ssl)); }
private ImageFormat GetImageFormat(IEntryImageInformation imageInfo) { switch (imageInfo.Mime) { case MediaTypeNames.Image.Jpeg: return ImageFormat.Jpeg; case "image/png": return ImageFormat.Png; case MediaTypeNames.Image.Gif: return ImageFormat.Gif; case "image/bmp": return ImageFormat.Bmp; default: return ImageFormat.Png; } }
public void Write(IEntryImageInformation picture, ImageSize size, Stream stream) { var bytes = StreamHelper.ReadStream(stream); var url = GetUrlAbsolute(picture, size, false); if (images.ContainsKey(url)) { images[url] = bytes; } else { images.Add(url, bytes); } }
private PictureDataContract SaveImage(IEntryImageInformation entry, EntryPictureFileContract pictureData) { if (pictureData == null) { return(null); } var parsed = ImageHelper.GetOriginal(pictureData.UploadedFile, pictureData.ContentLength, pictureData.Mime); pictureData.Id = entry.Id; pictureData.EntryType = entry.EntryType; var thumbGenerator = new ImageThumbGenerator(imagePersister); thumbGenerator.GenerateThumbsAndMoveImage(pictureData.UploadedFile, pictureData, ReleaseEventSeries.ImageSizes, originalSize: Constants.RestrictedImageOriginalSize); return(parsed); }
public override string GetUrlAbsolute(IEntryImageInformation picture, ImageSize size, bool ssl) { ParamIs.NotNull(() => picture); string url; if (picture.Version > 0) { url = string.Format("/EntryImg/{0}/{1}?v={2}", picture.EntryType, GetFileName(picture, size), picture.Version); } else { url = string.Format("/EntryImg/{0}/{1}", picture.EntryType, GetFileName(picture, size)); } return(VocaUriBuilder.Absolute(url, ssl)); }
public override VocaDbUrl GetUrl(IEntryImageInformation picture, ImageSize size) { ParamIs.NotNull(() => picture); string url; if (picture.Version > 0) { url = string.Format("/EntryImg/{0}/{1}?v={2}", picture.EntryType, GetFileName(picture, size), picture.Version); } else { url = string.Format("/EntryImg/{0}/{1}", picture.EntryType, GetFileName(picture, size)); } return(new VocaDbUrl(url, UrlDomain.Main, System.UriKind.Relative)); }
/// <summary> /// Returns an URL to entry thumbnail image. /// Currently only used for album and artist main images. /// /// Gets the URL to the static images folder on disk if possible, /// otherwise gets the image from the DB. /// </summary> /// <param name="urlHelper">URL helper. Cannot be null.</param> /// <param name="imageInfo">Image information. Cannot be null.</param> /// <param name="size">Requested image size.</param> /// <param name="fullUrl"> /// Whether the URL should always include the hostname and application path root. /// If this is false (default), the URL maybe either full (such as http://vocadb.net/Album/CoverPicture/123) /// or relative (such as /Album/CoverPicture/123). /// Usually this should be set to true if the image is to be referred from another domain. /// </param> /// <returns>URL to the image thumbnail.</returns> public static string ImageThumb(this UrlHelper urlHelper, IEntryImageInformation imageInfo, ImageSize size, bool fullUrl = false) { if (imageInfo == null) { return(null); } var shouldExist = ShouldExist(imageInfo); string dynamicUrl = null; // Use MVC dynamic actions when requesting original or an image that doesn't exist on disk. if (imageInfo.EntryType == EntryType.Album) { if (size == ImageSize.Original) { dynamicUrl = urlHelper.Action("CoverPicture", "Album", new { id = imageInfo.Id, v = imageInfo.Version }); } else if (shouldExist && !imagePersister.HasImage(imageInfo, size)) { dynamicUrl = urlHelper.Action("CoverPictureThumb", "Album", new { id = imageInfo.Id, v = imageInfo.Version }); } } else if (imageInfo.EntryType == EntryType.Artist) { if (size == ImageSize.Original) { dynamicUrl = urlHelper.Action("Picture", "Artist", new { id = imageInfo.Id, v = imageInfo.Version }); } else if (shouldExist && !imagePersister.HasImage(imageInfo, size)) { dynamicUrl = urlHelper.Action("PictureThumb", "Artist", new { id = imageInfo.Id, v = imageInfo.Version }); } } if (dynamicUrl != null) { return(fullUrl ? AppConfig.HostAddress + dynamicUrl : dynamicUrl); } if (!shouldExist) { return(GetUnknownImageUrl(urlHelper, imageInfo)); } return(imagePersister.GetUrlAbsolute(imageInfo, size, WebHelper.IsSSL(HttpContext.Current.Request))); }
public static string EntryThumbUrl(this UrlHelper url, IEntryImageInformation imageInfo, string songThumbUrl) { switch (imageInfo.EntryType) { case EntryType.Album: return(url.ImageThumb(imageInfo, ImageSize.TinyThumb)); case EntryType.Artist: return(url.ImageThumb(imageInfo, ImageSize.TinyThumb)); case EntryType.Song: return(songThumbUrl); default: return(string.Empty); } }
public void Write(IEntryImageInformation picture, ImageSize size, Stream file) { var path = GetPath(picture, size); if (string.IsNullOrEmpty(path)) return; EnsureDirExistsForFile(path); file.Seek(0, SeekOrigin.Begin); using (var f = File.Create(path)) { file.CopyTo(f); } file.Seek(0, SeekOrigin.Begin); }
/// <summary> /// Generates an URL to an entry image using the old folder structure for images. /// These are used for song lists and tags, and should eventually be migrated to the newer folder structure. /// </summary> /// <param name="urlHelper">URL helper.</param> /// <param name="imageInfo">Image information. Can be null.</param> /// <param name="size">Desired image size.</param> /// <param name="checkExists"> /// Whether to check that the image actually exists on disk. /// If this is true and the image doesn't exist, null will be returned. /// </param> /// <returns>Absolute URL to the image, or null if not found.</returns> public static string EntryImageOld(this UrlHelper urlHelper, IEntryImageInformation imageInfo, ImageSize size, bool checkExists = true) { if (imageInfo == null) { return(null); } if (checkExists) { var path = EntryImagePersisterOld.GetPath(imageInfo, size); if (!File.Exists(path)) { return(null); } } return(EntryImagePersisterOld.GetUrlAbsolute(imageInfo, size)); }
/// <summary> /// Generates thumbnails and writes the original file into external image files. /// </summary> public void GenerateThumbsAndMoveImage(Stream input, IEntryImageInformation imageInfo, ImageSizes imageSizes, int originalSize = Unlimited) { using (var original = ImageHelper.OpenImage(input)) { if (imageSizes.HasFlag(ImageSizes.Original)) GenerateThumbAndMoveImage(original, input, imageInfo, ImageSize.Original, originalSize); if (imageSizes.HasFlag(ImageSizes.Thumb)) GenerateThumbAndMoveImage(original, input, imageInfo, ImageSize.Thumb, ImageHelper.DefaultThumbSize); if (imageSizes.HasFlag(ImageSizes.SmallThumb)) GenerateThumbAndMoveImage(original, input, imageInfo, ImageSize.SmallThumb, ImageHelper.DefaultSmallThumbSize); if (imageSizes.HasFlag(ImageSizes.TinyThumb)) GenerateThumbAndMoveImage(original, input, imageInfo, ImageSize.TinyThumb, ImageHelper.DefaultTinyThumbSize); } }
public void Write(IEntryImageInformation picture, ImageSize size, Stream file) { var path = GetPath(picture, size); if (string.IsNullOrEmpty(path)) { return; } EnsureDirExistsForFile(path); file.Seek(0, SeekOrigin.Begin); using (var f = File.Create(path)) { file.CopyTo(f); } file.Seek(0, SeekOrigin.Begin); }
private static bool ShouldExist(IEntryImageInformation imageInfo) { // Image should have MIME type, otherwise it's assumed not to exist. return !string.IsNullOrEmpty(imageInfo.Mime); }
public string GetUrlAbsolute(IEntryImageInformation picture, ImageSize size, bool ssl) { var host = ssl ? AppConfig.StaticContentHostSSL : AppConfig.HostAddress; return string.Format("{0}/EntryImg/{1}/{2}", host, picture.EntryType, GetFileName(picture, size)); }
public bool HasImage(IEntryImageInformation picture, ImageSize size) { return images.ContainsKey(GetUrlAbsolute(picture, size, false)); }
public Stream GetReadStream(IEntryImageInformation picture, ImageSize size) { return new MemoryStream(images[GetUrlAbsolute(picture, size, false)]); }
public string GetUrlAbsolute(IEntryImageInformation picture, ImageSize size, bool url) { return picture.EntryType + "/" + picture.Id + "/" + size; }
public Stream GetReadStream(IEntryImageInformation picture, ImageSize size) { return File.OpenRead(GetPath(picture, size)); }
private string GetPath(IEntryImageInformation picture, ImageSize size) { var relative = string.Format(@"img\{0}\main{1}\{2}{3}", picture.EntryType, GetDir(size), picture.Id, ImageHelper.GetExtensionFromMime(picture.Mime)); return Path.Combine(staticRoot, relative); }
public string GetUrlAbsolute(IEntryImageInformation picture, ImageSize size, bool ssl) { return VocaUriBuilder.StaticResource(GetRelativeUrl(picture, size), ssl); }
private static string GetFileName(IEntryImageInformation picture, ImageSize size) { return GetFileName(picture.Id, picture.Mime, GetSuffix(size)); }
public string GetPath(IEntryImageInformation picture, ImageSize size) { return HttpContext.Current.Server.MapPath(string.Format("~\\EntryImg\\{0}\\{1}", picture.EntryType, GetFileName(picture, size))); }
private static string GetUnknownImageUrl(UrlHelper urlHelper, IEntryImageInformation imageInfo) { return urlHelper.Content("~/Content/unknown.png"); }
public bool HasImage(IEntryImageInformation picture, ImageSize size) { return File.Exists(GetPath(picture, size)); }