public static string CachedImage2(this HtmlHelper helper, string originalPath, string fileName, string fileName2, ThumbnailPicture thumbnail) { try { StringBuilder sb = new StringBuilder(); string formatString = "<img src=\"{0}\" alt=\"{1}\" width=\"{2}\" height=\"{3}\" />"; sb.AppendFormat(formatString, GetCachedImage(originalPath, fileName, thumbnail), fileName2, _width, _height); return sb.ToString(); } catch (Exception) { return "image file not found"; } }
///// <summary> ///// ///// </summary> ///// <param name="originalPath"></param> ///// <param name="fileName"></param> ///// <param name="thumbnail"></param> ///// <param name="scaleMode"></param> //public static void SaveCachedImage(string originalPath, string fileName, ThumbnailPicture thumbnail, ScaleMode scaleMode) //{ // CacheImage(originalPath, fileName, thumbnail.CacheFolder, thumbnail.PictureSize, scaleMode, false, 0); //} public static void SaveCachedImage(string originalPath, string fileName, ThumbnailPicture thumbnail) { string cachePath = HttpContext.Current.Server.MapPath("~/ImageCache/" + thumbnail.CacheFolder); string cachedImagePath = Path.Combine(cachePath, fileName); if (!File.Exists(cachedImagePath)) { CacheImage(originalPath, fileName, thumbnail.CacheFolder, thumbnail.PictureSize, thumbnail.ScaleMode, false, 0); } }
public static string CachedImage(this HtmlHelper helper, string originalPath, string fileName, ThumbnailPicture thumbnail, string className) { try { StringBuilder sb = new StringBuilder(); string formatString = "<img src=\"{0}\" alt=\"{1}\" class=\"{2}\" width=\"{3}\" height=\"{4}\" />"; //string formatString = "<img src=\"{0}\" alt=\"{1}\" class=\"{2}\" />"; string imageSrc = GetCachedImage(originalPath, fileName, thumbnail); if (string.IsNullOrEmpty(imageSrc)) return "image file not found"; sb.AppendFormat(formatString, VirtualPathUtility.ToAbsolute(imageSrc ?? ""), fileName, className ?? "", _width, _height); return sb.ToString(); } catch (Exception) { return "image file not found"; } }
public static string CachedImage(this HtmlHelper helper, string originalPath, string fileName, ThumbnailPicture thumbnail) { return CachedImage(helper, originalPath, fileName, thumbnail, null); }
public static string GetCachedImage(string originalPath, string fileName, ThumbnailPicture thumbnail) { if (string.IsNullOrEmpty(fileName) || !File.Exists(Path.Combine(HttpContext.Current.Server.MapPath(originalPath), fileName))) { return null; } string cacheFolder = thumbnail.CacheFolder; string result = Path.Combine("~/ImageCache/" + cacheFolder + "/", fileName); string cachePath = HttpContext.Current.Server.MapPath("~/ImageCache/" + cacheFolder); if (!Directory.Exists(cachePath)) Directory.CreateDirectory(cachePath); string cachedImagePath = Path.Combine(cachePath, fileName); if (File.Exists(cachedImagePath)) { GetImageSize(result); return result; } if (CacheImage(originalPath, fileName, cacheFolder, thumbnail.PictureSize, thumbnail.ScaleMode, thumbnail.UseBackgroundImage, thumbnail.Offset)) { GetImageSize(result); return result; } return null; }
public static string CachedImage(string fileName, ThumbnailPicture thumbnail) { StringBuilder sb = new StringBuilder(); string formatString = "<img src=\"{0}\" alt=\"{1}\" width=\"{2}\" height=\"{3}\" />"; string imageSrc = GetCachedImage(fileName, thumbnail); sb.AppendFormat(formatString, imageSrc, imageSrc, _width, _height); return sb.ToString(); }
public static string GetCachedImage(string fileName, ThumbnailPicture thumbnail) { if (string.IsNullOrEmpty(fileName) || !File.Exists(Path.Combine(HttpRuntime.AppDomainAppPath,"Content","Images", fileName))) { return null; } string cacheFolder = thumbnail.CacheFolder; string result = Path.Combine(HttpRuntime.AppDomainAppPath, "ImageCache" , cacheFolder , fileName); string cachePath = Path.Combine(HttpRuntime.AppDomainAppPath, "ImageCache" , cacheFolder); if (!Directory.Exists(cachePath)) Directory.CreateDirectory(cachePath); string cachedImagePath = Path.Combine(cachePath, fileName); if (File.Exists(cachedImagePath)) { GetImageSize(result); return "http://listelli.ua/ImageCache/"+ cacheFolder+"/"+ fileName; return result; } if (CacheImage(fileName, cacheFolder, thumbnail.PictureSize, thumbnail.ScaleMode, thumbnail.UseBackgroundImage, thumbnail.Offset)) { GetImageSize(result); return "http://listelli.ua/ImageCache/" + cacheFolder + "/" + fileName; return result; } return null; }